Regular Expression not to allow numbers - just Ara

2019-03-08 16:15发布

I found this regular expression for Arabic letters but it is also allowing numbers with letters. How can I change it to let it allow letters only ?

/[\u0600-\u06FF]/

标签: regex arabic
4条回答
做自己的国王
2楼-- · 2019-03-08 16:53

Probably you'd have to check what range the numbers match and exclude it (formally not include in brackets expression).

Here I've found another helpful source.

I'd suggest this for only letters

/[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FF]/

as this matches arabic digits only

/[\u0660-\u0669\u06F0-\u06F9]/

Edit:

I've found that there are two ranges for arabic and arabic-indic digits in unicode.

If you need a regex to match a line just then, when it contains arabic letters and numbers - use this:

/^[\u0600-\u06FF]*$/

If you want to also discourage arabic digits - use this:

/^[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FF]*$/

If you want to match a substring, not only a whole line, use this:

/\b[\s\u0600-\u065F\u066A-\u06EF\u06FA-\u06FF]*\b/
查看更多
Animai°情兽
3楼-- · 2019-03-08 16:53

First, concerning Arabic encoding in unicode, you might want to refer to this tables here

As for the regex you were given, [\u0600-\u06FF] is the range of all arabic characters on the unicode listing, definitely that includes even letters, control characters, white-space, and numbers.

My recommendation would be:

/[\u0600-\u06FF&&[^\U06F0-\06F9]]/

Which spans just everything minus the arabic numeric digits (0-9).

That subtracts a range from the 'super' range. Am just not sure whether your target regex dialect supports this.

查看更多
走好不送
4楼-- · 2019-03-08 16:56
[RegularExpression(@"^[\u0621-\u064A\u0660-\u0669a-zA-Z]+$", ErrorMessage = "You can enter Arabic or English characters only")] 

[RegularExpression(@"^[0-9]+$", ErrorMessage = "You can enter numbers only")]

[RegularExpression(@"^[a-zA-Z\0-9]+$",ErrorMessage = "You can enter numbers or english characters only")]

[RegularExpression(@"^[\u0621-\u064A\u0660-\u0669\0-9]+$", ErrorMessage = "You can enter numbers or arabic characters only")]

[RegularExpression(@"^[\u0621-\u064A\u0660-\u0669]+$", ErrorMessage = "You can enter arabic characters only")]

[RegularExpression(@"^[a-zA-Z]+$",ErrorMessage = "You can enter english characters only")]
查看更多
Summer. ? 凉城
5楼-- · 2019-03-08 16:59

I tried all solutions provided here, nothing worked, finally one solution worked for me for Arabic letters only

^[\u0621-\u064A\040]+$
查看更多
登录 后发表回答