About the Blog

  • The AC Multimedia blog is a web design and development blog containing articles and tutorials about the web and the stomping ground for Andy Crathorne, owner of AC Multimedia and web developer.

Recent Articles

Archive

Blogroll

RSS Blog Feed

  • Subscribe to our feed to receive the latest articles straight to your RSS news reader.

    RSS Blog Feed  RSS Blog Feed

Web Design Blogs - Blog Top Sites

RSS Comments Feed

  • Subscribe to the comments feed for "Validating an email address in PHP" to receive the latest comments straight to your RSS news reader.

    RSS Blog Feed  RSS Comments Feed

Blog Home  |  Comments (4)

Validating an email address in PHP

TUESDAY, MAY 13, 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.

Posted May 13, 2008 07:00 PM by Andy Crathorne | Permalink | Send to a Friend

Bookmark with:
Delicious Digg reddit Facebook StumbleUpon

Comments (4)

web pixy wrote:
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:)
Posted on 22-May-08 at 4:13 pm | Permalink

paris @ unitedworx cyprus web design wrote:
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!
Posted on 24-May-08 at 9:00 am | Permalink

Totonet wrote:
Nice tutorial, thanks for sharing with us. Very easy to undertand.
Posted on 03-Jul-08 at 6:57 am | Permalink

PHP Web Design wrote:
useful tutorial. it's a simple one. thanks for sharing it.
Posted on 12-Aug-08 at 2:08 pm | Permalink

Have something to say?

Have some interesting comments or thoughts on this blog? Perhaps you have some questions? Maybe you want to share your knowledge? Either way, write it below.













Security Image





Please note that all comments and URLs are subject to approval and may be amended to suit editorial style and subject matter. Website addresses will only be published after approval.