Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to validate if a plate of a Portuguese car has a valid structure.

Portuguese Plate is XX-XX-XX alpha numeric. It's Alpha numeric but you can′t have a number and a Char on the same position Example :

A5-99-AB -> It's wrong

55-99-AB -> it's right

Although there are sequences that are not yet valid according to PT plate rules (e.g 2 sets of letters AA-00-AA) this is something that I do not pretend to validate since it changes often.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
295 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try

let re = /^([A-Z]{2}|dd)-([A-Z]{2}|dd)-([A-Z]{2}|dd)$/;

console.log( re.test('A5-99-AB') );
console.log( re.test('55-99-AB') );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...