Ali
Ali

Reputation: 1152

Regular expression for license plate number in Iran with Persian letters and digits

I need a regular expression matching Iranian cars' license plate number. the combination consists of a two digit number followed by a Persian letter and then another three digit number
like in the picture below:

It's necessary to allow user to input English digits (1-9) because some browsers or operating systems don't support Persian digits, but the letter MUST be Persian and cuz it's always supported.

EDIT: Anyway I'm using c# in ASP.net MVC

Upvotes: 2

Views: 1938

Answers (3)

Use this if you want the patter for the full string.

/[0-9۰-۹]{2}[الف|ب-ی|D]{1,3}[0-9۰-۹]{3}ایران[0-9۰-۹]{2}/
  • [0-9۰-۹]{2}: Matches the first two digits, allowing for both English as well as Persian digits (accepts inputs regardless of user keyboard language).
  • [الف|ب-ی|D]{1,3}: Matches one to three Persian letters. It covers a range of Persian characters, including "الف," "ب," "ت," and more, as well as the Latin letter "D" for diplomatic cars. You can also add more letters to accept all types of plate numbers. Note: You should also limit the input length for this section of the string.
  • [0-9۰-۹]{3}: Matches the following three digits.
  • ایران: This part of the pattern matches the literal word "ایران."
  • [0-9۰-۹]{2}: Matches the final two digits of the license plate.

Upvotes: 0

Ali
Ali

Reputation: 1152

Found what I was looking for :

"[۱-۹\\d]{2}[\u0600-\u06FF][۱-۹\\d]{3}"  

Works flawlessly with MVC data annotations, which I'm currently using it for
[RegularExpression("[۱-۹\\d]{2}[\u0600-\u06FF][۱-۹\\d]{3}", ErrorMessage = "It's wrong!")]

Thank to Sniffer who helped me find the correct answer. :)
Wish you all find this helpful

Upvotes: 1

Ibrahim Najjar
Ibrahim Najjar

Reputation: 19423

You can match this from the left to the right using the following regex:

\d{2}[\u0600-\u06FF]\d{3}
  • \d{2} matches two consecutive digits.
  • [\u0600-\u06FF] matches a single letter.
  • \d{3} matches three consecutive digits.

Upvotes: 4

Related Questions