I want Regular Expression to accept only Arabic characters, Spaces and Numbers.
Numbers are not required to be in Arabic.
I found the following expression:
^[\u0621-\u064A]+$
which accepts only only Arabic characters while I need Arabic characters, Spaces and Numbers.
Just add 1-9
(in Unicode format) to your character-class:
^[\u0621-\u064A0-9 ]+$
OR add \u0660-\u0669
to the character-class which is the range of Arabic numbers :
^[\u0621-\u064A\u0660-\u0669 ]+$
You can use:
^[\u0621-\u064A\s\p{N}]+$
\p{N}
will match any unicode numeric digit.
To match only ASCII digit use:
^[\u0621-\u064A\s0-9]+$
EDIT: Better to use this regex:
^[\p{Arabic}\s\p{N}]+$
RegEx Demo
you can use
[ء-ي]
it worked for me in javascript Jquery forme.validate rules
for my example I want to force user to insert 3 characters
[a-zA-Zء-ي]
use this
[\u0600-\u06FF]
it worked for me on visual studio
With a lot of try and edit i got this for Persian names:
[گچپژیلفقهمو ء-ي]+$
^[\u0621-\u064Aa-zA-Z\d\-_\s]+$
This regex must accept Arabic letters,English letters, spaces and numbers
Simple, use this code:
^[-ۿ]+$
This works for Arabic/Persian even numbers.
function HasArabicCharacters(string text)
{
var regex = new RegExp(
"[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufc3f]|[\ufe70-\ufefc]");
return regex.test(text);
}
In PHP, use this:
preg_replace("/\p{Arabic}/u", 'x', 'abc123ابت');// will replace arabic letters with "x".
Note: For \p{Arabic}
to match arabic letters, you need to pass u
modifier (for unicode) at the end.
[\p{IsArabic}-[\D]]
An Arabic character that is not a non-digit