问题
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.
回答1:
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 ]+$
回答2:
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
回答3:
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ء-ي]
回答4:
use this
[\u0600-\u06FF]
it worked for me on visual studio
回答5:
With a lot of try and edit i got this for Persian names:
[گچپژیلفقهمو ء-ي]+$
回答6:
Simple, use this code:
^[-ۿ]+$
This works for Arabic/Persian even numbers.
回答7:
^[\u0621-\u064Aa-zA-Z\d\-_\s]+$
This regex must accept Arabic letters,English letters, spaces and numbers
回答8:
function HasArabicCharacters(string text)
{
var regex = new RegExp(
"[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufc3f]|[\ufe70-\ufefc]");
return regex.test(text);
}
回答9:
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.
回答10:
[\p{IsArabic}-[\D]]
An Arabic character that is not a non-digit
来源:https://stackoverflow.com/questions/29729391/regular-expression-arabic-characters-and-numbers-only