Regex to match LEGAL UK Number Plate [closed]
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this questioni have been working on matching a legal uk number plate with the following regex expression , however this only matches new number plates like JS07 ZAS not the old J62 LNX format, i need a expression to match both and i cant work out how to match both type of plates.
var plateregex = "([A-HJ-PR-Y]{2}([0][1-9]|[1-9][0-9])|[A-HJ-PR-Y]{1}([1-9]|[1-2][0-9]|30|31|33|40|44|55|50|60|66|70|77|80|88|90|99|111|121|123|222|321|333|444|555|666|777|888|999|100|200|300|400|500|600|700|800|900))[ ][A-HJ-PR-Z]{3}$";
if (!platetext.match(plateregex)) {
var answer = window.confirm ("Non LEGAL Plate Detected ...");
}
well here is the regex expression i made to match both type of plate开发者_高级运维s ^([A-HJ-PR-Y]{2,2}[056][0-9]\s?[A-HJ-PR-Y]{3,3})$|^([A-HJ-NP-Y]{1,3}[0-9]{2,3}?\s[A-Z]{3,3})$|^([A-Z]{1,3}\s?[0-9]{1,4}([A-Z]{1,1})?)$|^([0-9]{4,4}[A-Z]{1,3})$|^([A-Z]{1,2}\s?[0-9]{1,4})$|^([A-Z]{2,3}\s?[0-9]{1,4})$|^([0-9]{1,4}\s?[A-Z]{2,3})$
however this dosent match anything ? when it should do can you see any problems here for using with javascript regex ?
(Editing on behalf of OP) Here are some examples of UK registration plates that meet the OP's requirements. The pattern is double letter followed by double numeric followed by triple letter.
ML09WKY
BF59DZR
GF54LFK
GL59FVM
LA55JVL
LB59AHD
GF59WUC
A quick Google gave me these
/\b[a-z]{2}([1-9]|0[2-9]|6[0-9]|1[0-9])[a-z]{3}\b/i # current series
/\b[A-HJ-NP-Y]\d{1,3}[A-Z]{3}\b/ # previous series
/\b[A-Z]{3}\d{1,3}[A-HJ-NP-Y]\b/ # previous series
/\b(?:[A-Z]{1,2}\d{1,4}|[A-Z]{3}\d{1,3})\b/ # old series - letters first
/\b(?:\d{1,4}[A-Z]{1,2}|\d{1,3}[A-Z]{3})\b/ # old series - digits first
Looks like you'll have to test them individually.
Angular ng-pattern:
ng-pattern="/\b[a-z]{2}([1-9]|0[2-9]|6[0-9]|1[0-9])[a-z]{3}|[A-HJ-NP-Y]\d{1,3}[A-Z]{3}|[A-Z]{3}\d{1,3}[A-HJ-NP-Y]|(?:[A-Z]{1,2}\d{1,4}|[A-Z]{3}\d{1,3})|(?:\d{1,4}[A-Z]{1,2}|\d{1,3}[A-Z]{3})\b/i"
精彩评论