Noman
Noman

Reputation: 4116

Javascript regex to allow specific characters in arabic

How to write regex to allow specific characters or digits in Arabic language

i have this regex but it does match all arabic and english

   /^[-\sa-zA-Z,\u0600-\u06FF]+$/

i want to restrict it to write only arabic letters with space (\s) and dash -

For future use regex should be efficient to match provided group only for arabic langauge it could be

  1. Arabic letters with space
  2. Arabic letters with digits only
  3. Arabic letters with space and digits

Upvotes: 3

Views: 1549

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626932

Use

/^[-\s\u0621-\u064A\u0660-\u0669\u066E-\u06D5\u06EE\u06EF\u06FA-\u06FC\u06FF\u0‌6F0-\u06F9]+$/

Here, \u06F0-\u06F9 range stands for extended digits and \u0621-\u064A\u0660-\u0669\u066E-\u06D5\u06EE\u06EF\u06FA-\u06FC\u06FF stand for all letters.

See legend (taken from Wikipedia) (adjust as you see fit using the table below):

enter image description here

Upvotes: 3

Related Questions