Here are two code snippets to verify email addresses, which is quite useful when you wish to validate a form with Javascript or PHP, avoiding users to write anything as email.
Verify email format with Javascript
Insert this code between <head> and </head> tags of your HTML document :
Insert a form between <body> and </body> tags :
Eventonsubmit calls checkMail() function and gives him text value of email field. Email field is identified by ID email.
Verify email format with PHP
This little PHP function allows you to check if the user wrote a valid email address that may exist. You call this function when you’re checking POST values after form submission.
if ((!ereg(“.+\@.+\..+”, $addr)) || (!ereg(“^[a-zA-Z0-9_@.-]+$”, $addr)))
RETURN FALSE;
else
RETURN TRUE;
}
// Use :
if(!validMail(‘infoaddress.com’)) {
echo “Your email address is invalid!”;
}
It won’t prove real existence of the email address, but it will avoid the user from writing stupid stuff.
Ce message est également disponible en : French
Thanks for the Code , I was searching it and it worked in the way I want
Thank you for writing such a beautiful articles. it’s really informative for me
bitte schön
it runs two php scripts when followed first adds the deny from IP to the .ht access that’s in the root below all directories {except the directory containing the error pages and php scripts for blacklisting
thanks a lot! It’s really help me
this error is detected and i can’t fised it
Deprecated: Function ereg() is deprecated in C:\Program Files\EasyPHP-5.3.3.1\www\Admin-php\phpcheck.php on line 29
Invalid email