Flash, Photoshop and Website Creation.

PHP - Email Verification

Breif

So while working on another project of mine I found that I needed to verify the email address that the user has submitted. I looked around on the internet and found a very useful piece of code which will do this.


$email = something@yourdomain.com
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
$message = "Your Email address appears to be invalid.";
} else {
$message = "Your Email address appears to be invalid.";
}
?>

This ‘eregi’ function checks if the string inside the email variable follows the structure given. So it makes sure that there are no illegal characters. There is only 1 @ character and the last ‘.’ is at least 2 characters away from the @ character. If you have any other ways of doing this, please comment below.

Be Sociable!

What do you think?

Your Name Please.

Your Email, We Will Keep It Secret...

Your Website, If You Have One.