I have this email regex, and i would like to make same thing with a name regex, so you can't write numbers in a name, how should i change it?
if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
$emailError = 'You entered an invalid email address.';
$hasError = true;
}
I know that [a-z0-9_.-] means that a-z 0-9 and _ . - is usable. But i want to only use a-z and this is why my brain is breaking across, as i don't understand the whole sentence, could anyone "translate" it to only use a-z and no numbers neither _ - .? I would like it to be changed to a name regex, so people can't write numbers in their name.
I understand that i can write
if (!preg_match("/^[[:alnum:]][a-z]*@[a-z]+\.[a-z]{2,4}$/i", trim($_POST['name']))) {
$nameError = 'You entered invalid characters in your name.';
$hasError = true;
}
but for me it doesn't make any sense, how i should enter that into the regex above.
but i could also type in this? so i say if it contains 0-9 then its invalid? but i don't know what it means all these characters in the sentence.
if (preg_match("/^[[:alnum:]][0-9]*@[0-9]+\.[0-9]{2,4}$/i", trim($_POST['name']))) {
$nameError = 'You entered invalid characters in your name.';
$hasError = true;
}
I tried to research about "preg_match" but i can't find an explanation, so i can make my a regex for "preg_match" on my own