So im using jquery validation on my script to only allows certain characters. I've had a request to allow the script to use arabic characters aswell. How would i do this?
Heres my current code:
$.validator.addMethod(
"legalname",
function(value, element) {
return this.optional(element) || /^[a-zA-Z0-9()._\-\s]+$/.test(value);
},
"Illegal character. Only points, spaces, underscores or dashes are allowed."
);
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).
The Difference Between \s and \s+ For example, expression X+ matches one or more X characters. Therefore, the regular expression \s matches a single whitespace character, while \s+ will match one or more whitespace characters.
*. * , returns strings beginning with any combination and any amount of characters (the first asterisk), and can end with any combination and any amount of characters (the last asterisk). This selects every single string available.
The Arabic alphabet, called Al-abjadiyah, has 28 letters. All 28 letters are consonants, and most letters have four different forms. Vowels do exist in Arabic – but we'll explain all about Arabic letter forms and vowels a bit later on!
Via this site you can easily create unicode regex for many languages:
Arabic:
[\u0600-\u06FF]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With