Last active
December 31, 2022 12:18
-
-
Save web-elite/809ad8e0f1936aa65320f4691dc9bad1 to your computer and use it in GitHub Desktop.
filter inputs with only number or only alphabet or only persian letters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$('input.number-filter,.number-filter [type="number"],.number-filter [type="tel"]').on("keydown contextmenu drop", function(event) { | |
const valid = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "ArrowRight", "Backspace", "ArrowLeft", "ArrowUp", "ArrowDown"]; | |
if (!valid.includes(event.key)) { | |
event.preventDefault(); | |
} | |
}) | |
$('.persian-filter input[type*="text"],.persian-filter textarea, input.persian-filter').on("keydown contextmenu drop", function(event) { | |
const valid = ["الف", "ب", "پ", "ت", "ث", "ج", "چ", "ح", "خ", "د", "ذ", "ر", "ز", "ژ", "س", "ش", "ص", "ض", "ط", "ظ", "ع", "غ", "ف", "ق", "ک", "گ", "ل", "م", "ن", "و", "ه", "ی", "َ", "ُ", "ِ", "ّ", "ۀ", "آ", "ـ", ",", "،", "ريال", "ٍ", "ٌ", "ً", "ة", "ؤ", "؛", "إ", "أ", "ء", " ", "ArrowRight", "Backspace", "ArrowLeft", "ArrowUp", "ArrowDown"]; | |
if (!valid.includes(event.key)) { | |
event.preventDefault(); | |
} | |
}) | |
$('.english-filter input[type*="text"],.english-filter textarea,input.english-filter').on("keydown contextmenu drop", function(event) { | |
const valid = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", " ", "ArrowRight", "Backspace", "ArrowLeft", "ArrowUp", "ArrowDown"]; | |
if (!valid.includes(event.key)) { | |
event.preventDefault(); | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment