This allows things like YJ1313 or JDTZ11. What I am looking for is to update this regex to allow multi values separated by coma, say YJ1313,JDTZ11,XX1111,AABB88,YY1111,RRTT11
User’s input in form. Those are Chilean license plates and the user so far could enter just one but they want being able to enter several.
The format is either 2 letters and 4 digits or 4 letters and 2 digits
$errors = [];
// $input should contain the input by the user
// use 'trim' to ignore any spaces around commas
$licensplates = array_map('trim', explode(',', $input));
foreach ($licenseplates as $licenseplate) {
if (!preg_match('^[a-z-A-Z]{4}[0-9]{2}|^[a-z-A-Z]{2}[0-9]{4}$', $licenseplate)) {
$errors[] = sprintf('Licence plate "%s" is invalid', $licenseplate);
}
}
// do something nice with the errors please
// like rendering them in the form
// this is just an example
if (!empty($errors)) {
echo 'Computer says no!';
var_dump($errors);
exit;
}