It seems to be working correctly, but if you put leading characters it doesn't check that and if you put ending characters it doesn't check that.
I want to make sure a string is in this format:
6 Numbers | Hyphen | 1 Number | A-Z any case | Hyphen | 5 Numbers
So like this 123456-1a-12345
and 123456-1A-12345
should work.
$string = 'this12345-1A-12345'; // This works, and it shouldn't
$string = '12345-1A-12345this'; // This also works and it shouldn't
$pattern = "([0-9]{6}[-]{1}[0-9]{1}[A-Za-z]{1}[-]{1}[0-9]{5})";
echo preg_match($pattern, $string);
What am I doing wrong? Sorry I am really new to preg_match
, and I can't find any good libraries on syntax.