Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

How to check if any Arabic character exists in the string with javascript language

like image 262
Mhd.Jarkas Avatar asked Dec 15 '10 02:12

Mhd.Jarkas


People also ask

How do I check if a string contains an Arabic character?

https://www.npmjs.com/package/is-arabic It checks both Arabic and Farsi letters and Unicode as well. It also checks for Arabic symbols, Harakat, and numbers. You can also make it check for a certain number of characters.By default it checks if the whole string is Arabic.

How do I know if a string is Arabic or English?

You can usually tell by the code points within the string itself. Arabic occupies certain blocks in the Unicode code space. It's a fairly safe bet that, if a substantial proportion of the characters exist in those blocks (such as بلدي الحوامات مليء الثعابينة ), it's Arabic text.


1 Answers

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 
like image 66
casablanca Avatar answered Sep 27 '22 18:09

casablanca