Miscellaneous

  Home arrow Miscellaneous arrow E-mail Validation with PHP
MISCELLANEOUS

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

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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    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

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap