Miscellaneous
  Home arrow Miscellaneous arrow E-mail Validation with PHP
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

E-mail Validation with PHP
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2004-06-18

    Table of Contents:
  • E-mail Validation with PHP
  • Finishing it off

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    E-mail Validation with PHP


    (Page 1 of 2 )

    This tutorial will show you how to check to see if an E-mail address is valid.

    By : David Duke

    This tutorial has been graciously provided by spoono.com

    When you register on at a website, the site normally checks if the e-mail address that you enter is in a valid format. This is done by using what called a Regular Expression. What we need to do is check if a string (eg $email) matches the regular expression:

    <?php
    ereg
    ("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]",
         
    $email);
    ?>

    At the moment that only checks the string ($email), but does not does not output anything.So next we need to write an IF statement that returns a boolean value, if the string does not match the regular expressions.

    <?php
    if (eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]"$email)) 
    {
       return 
    FALSE;
    }
    ?>

    That is the basic validation bit, but now we can do even more validation. What we will do next is check the domain name after the @ is a real domain name. (We do this by checking if an MX record exists for that domain name and then we check if port 25 is open for that domain name, which makes sure that the domain name is in use.)

    <?php
    list($Username$Domain) = split("@",$email);
    if(
    getmxrr($Domain$MXHost)) 
    {
       return 
    TRUE;
    }
    else 
    {
       if(
    fsockopen($Domain25$errno$errstr30)) 
       {
          return 
    TRUE
       }
       else 
       {
          return 
    FALSE
       }
    }
    ?>

    More Miscellaneous Articles
    More By Codewalkers


       · Good idea I think I'll use it and try it out
       · I've attempted to try this out and I get this error.. Warning: fsockopen():...
       · Excellent piece of work, explained nicely.Keep it up.Rakesh
       · Brilliant stuff, really simple to follow and extremely usefull!!Keep up the good...
       · This is really excellent piece of code. Can we check whether the username is there...
       · According to the PHP manual getmxrr(0 should not be used for email validation.
       · Don't forget, getmxrr() doesn't work in windows. There is a nice windows alternative...
       · There plus character should be treated because in some systems like gmail you can...
     

    MISCELLANEOUS ARTICLES

    - Stopping CSRF Attacks in Your PHP Applicatio...
    - Quick and Dirty AJAX Tutorial
    - Flickr Puzzle Mashup
    - The PAVISE of Security
    - Creating a CAPTCHA with PHP
    - Sending SMS Thru HTTP
    - The Postal Fix - Part 2
    - Adding Mail with Exim
    - The Postal Fix - Part 1
    - Create Your Own Custom API
    - Adding Drop Shadows with PHP
    - Writing a Basic Authentication System in PHP
    - Overlapping Images with GD
    - Using Sockets in PHP
    - Dynamic CSS with PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway