Learner Learner - 3 years ago 159
Javascript Question

Javascript regular expression for vehicle number

Would someone write a regular expression to validate a vehicle number in text box with the below format:


MH-01-XX-0001


i.e. Alphabets in 1st 2 characters, special character '-', then two numbers, special character '-', then two alphabets, special character '-' and then 4 digit number.

Answer Source

This a very simple tasks. Try this:

^[A-Z]{2}-\d{2}-[A-Z]{2}-\d{4}$
  • The [A-Z] means the capital alphabet characters.
  • The \d means digits.
  • The numbers between curved brackets {..} means how many times the preceding should be repeated.
  • The ^ means the beginning of the string and the $ means the end of it.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download