I am not good at regular expression. How to do a php regular expression, make a judge if a string first word is (a-h), second word is @, third part are numbers(length range from 4-15)?
Is my php regular expression right?
$title = 'c@356920'; //h@907659042423
if (preg_match ("/^[a-h]{1}\@[0-9]{4,15}/i", $title)) {
echo 'ok';
}
If that is all you need to match, you need to add the rear anchor sign, (
$). So you need to change your code from that to this:You also do not need to escape the
@symbol. Your regex, as is, will match any string which starts with that sequence, but allows for any other amount of data to follow afterwards (from the question I can’t tell if that is something you are after or not).