How can i do a check to make sure an email address entered is valid?
Validate Email Address?
Collapse
X
-
Regex is what you need. Mine is poor but this is one I have used in the past:
Some regex expert may not agree though! Its a start anyway.Code:if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email)) echo ("Valid"); else echo ("Bad Email.");
Cheers. -
just out of interest, why are you capturing the character classes (doesn't make sense to me)?
I'm using this one (just another RegEx):
Code:/^[\w.%+\-]+@[[:alnum:].\-]+\.[a-z]{2,4}$/i/^ from the beginningCode:/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/
$/ to the end
[a-zA-Z0-9] look for any of those characters
+ at least once occurring
* zero or more occurring
() remember the captured charactersComment
Comment