Regular Expression Arabic characters and numbers only

我的未来我决定 提交于 2019-11-27 00:57:20

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:

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

Simple, use this code:

^[؀-ۿ]+$

This works for Arabic/Persian even numbers.

Mousa Ibrahim

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

This regex must accept Arabic letters,English letters, spaces and 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!