Wednesday, 4 October 2017

JavaScript enter Arabic letters validation





I am working on a simple PHP website where the user has to enter data in a form,



and if the user didn't enter Arabic letters I want to show a warning message "Arabic only" , I tried using the code below but it shows the warning message if I entered both Arabic or English letters.





Answer



In your example, you need to create a RegEx object to test against.




var isArabic = /[\u0600-\u06FF\u0750-\u077F]/;
if (isArabic.test(x)){
...
}


There's no coercion from a string to a regular expression in JavaScript.


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...