Validating an email address in PHP
May 13th, 2008
A small tutorial and example script to validate the format of an e-mail address. This is very useful when capturing e-mail addresses from visitors.
If you’re using the e-mail address to send out important information then it’s advisable to ask the user to enter it twice, to account for misspelling.
<?php
#email address to validate
$email = "name@domain.com";
#validate format
if(!eregi("^[_&a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+
(.[a-z0-9-]+)*(.[a-z]{2,4})$", $email)) {
echo 'Invalid format of email address';
}
?>
All done!
That’s it! All you need to validate the format of an e-mail address. This script doesn’t verify that the mailbox nor the domain actually exist. For more information on any of the code featured above visit www.php.net for the online manual.

Very nice tutorial, I loved it and it was very helpful! It seems so easy but if I had to figure it out, it would take me a while:)
this is simple, i did the same through javascript in many sites. the best method of all thought is verification through email. that is the only method that will force users to enter their actual email adress and not a fake one!
Nice tutorial, thanks for sharing with us. Very easy to undertand.
useful tutorial. it’s a simple one. thanks for sharing it.
Great tutorial, a lot of designers miss out on this most of the time.