Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include Arabic characters in JavaScript regular expression?

Tags:

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."
);
like image 716
Josh Fradley Avatar asked Oct 11 '12 19:10

Josh Fradley


People also ask

How do you denote special characters in regex?

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).

What does %s mean in regex?

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.

What is the use of * in regular expression?

*. * , 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.

What is the Arabic alphabet called?

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!


1 Answers

Via this site you can easily create unicode regex for many languages:

Arabic:

[\u0600-\u06FF]
like image 166
Mohsen Afshin Avatar answered Oct 03 '22 04:10

Mohsen Afshin