So I just learned about preg_match in PHP the other day and now i’m trying to preg_match a license plate. It should check for this:
9a-4e-yy, so a - and before and after that numbers or letters and then a - again and more numbers or letters. But it has to be exactly 2 numbers or letters next to each other, not more.
For now I have this code:
return preg_match("/^([0-9])"."([0-9])"."(\-([0-9])"."([0-9]))"."(\-([0-9])"."([0-9]))$/", $kenteken );
But that only checks on numbers.
I hope you guys could help me to get it work with letters too.
Thanks in advance!
[0-9]matches only numbers. If you want to match numbers or letters then you need[0-9A-Za-z].A full regex to do what you want is
^[0-9A-Za-z]{2}(-[0-9A-Za-z]{2}){2}$