Does PHP have a function built for validating email addresses on a form, or do you have to write that type of script yourself? I don’t mind writing the script, I’m just wondering.
@SyCoAug 12.2008 — #There no validate_email() function. Regular expressions with preg_match() are as close as you'll get. What expression you use depends on how through you want to be.
I'd suggest reading a few different websites about it as there are lots of things to consider and few get it entirely correct.
@NogDogAug 13.2008 — #[url=http://www.php.net/filter_var]filter_var[/url]() with the FILTER_VALIDATE_EMAIL filter: [code=php] $email = trim($_POST['email']); if(filter_var($email, FILTER_VALIDATE_EMAIL) == false) { // it is invalid } [/code] Note that for some reason filter_var() does not return false if the last character is a newline, but if you trim() it first, then that becomes a non-issue.
@skywalker2208Aug 13.2008 — #[url=http://www.php.net/filter_var]filter_var[/url]() with the FILTER_VALIDATE_EMAIL filter: [code=php] $email = trim($_POST['email']); if(filter_var($email, FILTER_VALIDATE_EMAIL) == false) { // it is invalid } [/code] Note that for some reason filter_var() does not return false if the last character is a newline, but if you trim() it first, then that becomes a non-issue.[/QUOTE] I will have to remember that.