$string="1234-ABCD-EFGH";
preg_match("~[0-9]{4}-[A-Z]{4}-[A-Z]{4}~", $string, $matches);
print_r($matches);
This code will output the $matches array that contains the match information.
preg_match
will return true
or false
depending on whether the string matched.
If you prefer to also match lower case characters, use this one:
preg_match("~[0-9]{4}-[A-Za-z]{4}-[A-Za-z]{4}~", $string, $matches);
1
solved php – Regular expression to validate this string [closed]