I am trying to implement regex validation for passport number.
My requirement is
I tried with the below regular expression
^(?!0{3,20})[a-zA-Z0-9]{3,20}$
This seems to work for most of the cases, but incase my text contains 3 or more leading zeros, it seems to fail. Such as '00000001'.
Example Matches
Any help would be much appreciated.
The valid passport number of India must satisfy the following conditions: It should be eight characters long. The first character should be an upper case alphabet. The next two characters should be a number, but the first character should be any number from 1-9 and the second character should be any number from 0-9.
Enter the Passport Number exactly as it is shown on the title page of your passport, including any letters or numbers pre-printed on the page. If you enter the Passport Number incorrectly, your Visa record will not be found. The Passport Number may only include the letters A to Z and the numbers 0 to 9.
What does the passport reference number consist of? The passport reference number is a 12-digit code comprising numbers and alphabets.
The passport reference number is a 12 digit unique code that is the combination of alphabets and numerals. The composition of the Passport Reference Number is detailed below, The first four digits of the Passport Reference Number represent the city or the place from where the application is made.
What about this?
^(?!^0+$)[a-zA-Z0-9]{3,20}$
Instead of saying 'reject values with 3-20 zeros', we can just say 'reject anything that only contains zeros (regardless of the length, since <3 and >20 fail anyway)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With