How to check if any Arabic character exists in the string ( javascript )

According to Wikipedia, Arabic characters fall in the Unicode range 0600 - 06FF. So you can use a regular expression to test if the string contains any character in this range:

var arabic = /[\u0600-\u06FF]/;
var string = 'عربية‎'; // some Arabic string from Wikipedia

alert(arabic.test(string)); // displays true

how it work for me is

$str = "عربية";
if(preg_match("/^\x{0600}-\x{06FF}]+/u", $str))echo "invalid";
else echo "valid";

You can check extended range of Arabic character

0x600  - 0x6ff
0x750  - 0x77f
0xfb50 - 0xfc3f
0xfe70 - 0xfefc

So expression will look more like "/^\x{0600}-\x{06FF}\x{0750}-\x{077f}]+/u"
Good Luck


function isArabic(text) {
    var pattern = /[\u0600-\u06FF\u0750-\u077F]/;
    result = pattern.test(text);
    return result;
}

Ranges for Arabic characters are:

0x600  - 0x6ff

0x750  - 0x77f

0xfb50 - 0xfc3f

0xfe70 - 0xfefc

Tags:

Javascript