Forum Moderators: coopster
I have been trying to work out what is wrong with my email validation preg.
Here is the regex, and below is my understanding of it:
^[A-Za-z0-9]+([._-]{1}[A-Za-z0-9]+){0,}@[A-Za-z0-9]+([._-]{1}[A-Za-z0-9]+){0,}\.[A-Za-z]{2, 6}$
starting with: one or more in the ranges A-Za-z0-9
followed by 0 or more of: 1 from .-_ followed by one or more in the ranges A-Za-z0-9
followed by @
then: one or more in the ranges A-Za-z0-9
followed by 0 or more of: 1 from .-_ followed by one or more in the ranges A-Za-z0-9
followed by .
followed by between 2 and 6 characters from A-Za-z
and it doesn't work. Is my logic flawed?
function validate_email($email)
{
return preg_match('/^[A-Za-z0-9]+([._-]{1}[A-Za-z0-9]+){0,}@[A-Za-z0-9]+([._-]{1}[A-Za-z0-9]+){0,}\.[A-Za-z]{2, 6}$/', $email);
}
Welcome to WebmasterWorld!