Hello everyone here...
I need to build up a swing application related to vehicle registration and in which i want to do input the vehicle number of indian standard, like
Based on the Wikipedia spec:
^[A-Z]{2}[ -][0-9]{1,2}(?: [A-Z])?(?: [A-Z]*)? [0-9]{4}$
AP-05-BJ-9353
TN-35-AB-638
MH-03-C-3843
Expression:
^[A-Z]{2}[-][0-9]{1,2}[-][A-Z]{1,2}[-][0-9]{3,4}$
Check the expression here: https://regexr.com/
^[A-Z]{2}\s[0-9]{1,2}\s[A-Z]{1,2}\s[0-9]{1,4}$
The above regex will work for the following types
DL 01 AA 1111
DL 0 AA 1111
DL 1 A 1111
DL 0 A 11
DL 01 AA 111
If you are looking for number plate(VRN) then use following regex
^[A-Z|a-z]{2}\s?[0-9]{1,2}\s?[A-Z|a-z]{0,3}\s?[0-9]{4}$
Try this
^[A-Z]{2}\s[0-9]{2}\s[A-Z]{2}\s[0-9]{4}$
^
means start of string
[A-Z]{2}
means 2 characters in the range of A through Z
\s
means white space
[0-9]{2}
means 2 characters in the range of 0 through 9
\s
means white space
[A-Z]{2}
means 2 characters in the range of A through Z
\s
means white space
[0-9]{4}
means 4 characters in the range of 0 through 9
$
means end of string
Based on what you said in your question this should be a very broad check against proper format, but I have a feeling that there are more specific regulations on how the license plates are numbered. Let me know if there are additional constraints for the regex.
just check it out for whitespace only...
function isValidNumber($Number){
$pattern = "^[a-zA-z]{2}\s[0-9]{2}\s[0-9]{4}$";
if (eregi($pattern, $Number)){
return true;
}
else {
return false;
}
}