0

I want a Regex for the Saudi national ID

The length is always 10 numbers

It always starts with "1" or "2"

1 Answers1

0

\b[12]\d{9}\b

[12] - 1 or 2

\d{9} - \d(number) times

It is useful to use sites like this one when you try to come up with a regex: https://regex101.com/

Sebastian
  • 551
  • 2
  • 8
  • You need a word break (`\b`) at the beginning and end; else you will match, for example, `2123456789` in `321234567890`. See [this](https://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks) on formatting your code. Lastly, nearly all readers will know about regex101.com; the value of that site it to enter your regex and example strings then click "share and save" to get a URL to paste into your answer. – Cary Swoveland May 21 '20 at 02:15