正则表达式仅限阿拉伯字符和数字

Regular Expression Arabic characters and numbers only

我希望正则表达式只接受阿拉伯字符空格数字

数字不需要使用阿拉伯语。

我找到了以下表达式:

^[\u0621-\u064A]+$

它只接受阿拉伯字符,而我需要阿拉伯字符、空格和数字。

您可以使用:

^[\u0621-\u064A\s\p{N}]+$

\p{N} 将匹配任何 unicode 数字。

要仅匹配 ASCII 数字,请使用:

^[\u0621-\u064A\s0-9]+$

编辑:最好使用这个正则表达式:

^[\p{Arabic}\s\p{N}]+$

RegEx Demo

只需将 1-9(Unicode 格式)添加到您的字符中-class:

^[\u0621-\u064A0-9 ]+$

或将 \u0660-\u0669 添加到字符 -class 即 range of Arabic numbers :

^[\u0621-\u064A\u0660-\u0669 ]+$

使用这个

[\u0600-\u06FF]

它对我有用 visual studio

你可以使用 [ء-ي] 它适用于 javascript Jquery forme.validate 规则

对于我的示例,我想强制用户插入 3 个字符

[a-zA-Zء-ي]

function HasArabicCharacters(string text)

{

    var regex = new RegExp(

        "[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufc3f]|[\ufe70-\ufefc]");

    return regex.test(text);
}
[\p{IsArabic}-[\D]]

不是非数字的阿拉伯字符

在PHP中,使用这个:

preg_replace("/\p{Arabic}/u", 'x', 'abc123ابت');// will replace arabic letters with "x".

注意\p{Arabic}匹配阿拉伯字母,需要在末尾加上u修饰符(对于unicode)

经过大量尝试和编辑,我得到了这个波斯名字:

[گچپژیلفقهمو ء-ي]+$

很简单,使用这个代码:

^[؀-ۿ]+$

这适用于 Arabic/Persian 个偶数。

^[\u0621-\u064Aa-zA-Z\d\-_\s]+$

此正则表达式必须接受阿拉伯字母、英文字母、空格和数字

The posts above include much more than arabic (MSA) characters, it includes persian, urdu, quranic symbols, and some other symbols. The arabic MSA characters are only (see Arabic Unicode)

[\u0621-\u063A\u0641-\u0652] 

要允许阿拉伯语 + 英语字母在一个字段中具有最小和最大允许字符数,试试这个,测试 100%: ^[\u0621-\u064A\u0660-\u0669a-zA-Z\-_\s]{4,35}$ A- 允许的阿拉伯英文字母。 B- 不允许使用数字。 C- {4,35} 表示允许的 Min,Max 个字符。 更新:提交时:可接受带空格的英文单词,但无法提交带空格的阿拉伯语单词!

All cases tested

仅适用于英语和阿拉伯数字的正则表达式

function HasArabicEnglishNumbers(text)

{

    var regex = new RegExp(

        "^[\u0621-\u064A0-9]|[\u0621-\u064A\u0660-\u0669]+$");

    return regex.test(text);
} 
@Pattern(regexp = "^[\p{InArabic}\s]+$")

接受阿拉伯数字和字符

我总是在我的应用程序中使用这些来控制用户输入

public static Regex IntegerString => new(@"^[\s\da-zA-Zء-ي]+[^\.]*$");
public static Regex String => new(@"^[\sa-zA-Zء-ي]*$");
public static Regex Email => new(@"^[\d\@\.a-z]*$");
public static Regex Phone => new(@"^[\d\s\(\)\-\+]+[^\.]*$");
public static Regex Address => new(@"^[\s\d\.\,\،\-a-zA-Zء-ي]*$");
public static Regex Integer => new(@"^[\d]+[^\.]*$");
public static Regex Double => new(@"^[\d\.]*$");

这是个有用的例子

public class Test {

public static void main(String[] args) {
    String thai = "1ประเทศไทย1ประเทศไทย";
    String arabic = "1عربي1عربي";

    //correct inputs
    System.out.println(thai.matches("[[0-9]*\p{In" + Character.UnicodeBlock.THAI.toString() + "}*]*"));
    System.out.println(arabic.matches("[[0-9]*\p{In" + Character.UnicodeBlock.ARABIC.toString() + "}*]*"));

    //incorrect inputs
    System.out.println(arabic.matches("[[0-9]*\p{In" + Character.UnicodeBlock.THAI.toString() + "}*]*"));
    System.out.println(thai.matches("[[0-9]*\p{In" + Character.UnicodeBlock.ARABIC.toString() + "}*]*"));
    
}

}