Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression not to allow numbers - just Arabic letters

Tags:

regex

arabic

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]/
like image 340
Noon Avatar asked Sep 20 '12 18:09

Noon


People also ask

How do I check if a string contains an Arabic character?

Use the count option to check if a string includes Arabic characters. It has full support.

Can you use regex on numbers?

The regex [0-9] matches single-digit numbers 0 to 9. [1-9][0-9] matches double-digit numbers 10 to 99. That's the easy part. Matching the three-digit numbers is a little more complicated, since we need to exclude numbers 256 through 999.

How do you ignore a regular expression?

To match any character except a list of excluded characters, put the excluded charaters between [^ and ] . The caret ^ must immediately follow the [ or else it stands for just itself.


2 Answers

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/
like image 114
Krzysztof Jabłoński Avatar answered Sep 19 '22 00:09

Krzysztof Jabłoński


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

^[\u0621-\u064A\040]+$
like image 27
amal50 Avatar answered Sep 20 '22 00:09

amal50