I need a regular expression in Javascript, as well as in PHP, for Indian vehicle NUMBER.
Here is the conditions list:
(x)(y)(z)(m)(a)(b)(c)
1. (x) contains only alphabets of length 2.
2. (y) may be - or single space ' '.
3. (z) contains only numbers of length 2.
4. (m) may be or , or single space ' '.
5. (a) must be one or two alphanumeric followed by an alpha.
6. (b) must be identical to (y).
7. (c) contains only numbers of length 4.
Here are some examples of valid vehicle numbers:
- RJ-14,NL-1234
- RJ-01,4M-5874
- RJ-07,14M-2345
- RJ 07,3M 2345
- RJ-07,3M-8888
- RJ 07 4M 2345
- RJ 07,4M 2933
and some invalid ones (with reason):
- RJ-07 3M 1234 (both (y) and (b) should be same).
- RJ-07 M3-1234 ((a) must ends with alphabet).
- rj-07 3M-123 (length of (c) must be 4).
Here’s the regex… this should be safe in most/all langauges:
The reason why I have the regex repeated twice with an “or” in the middle is to meet your criteria that “both (y) and (b) should be same.”