Miscellaneous
  Home arrow Miscellaneous arrow Page 6 - Form and Spelling Validation
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 
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

Form and Spelling Validation
By: Matt Wade
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2003-07-20

    Table of Contents:
  • Form and Spelling Validation
  • Common Form Validations
  • Spell Checking
  • Summary

  • 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


    Form and Spelling Validation -


    (Page 6 of 14 )

    Validating email addresses can be tricky business. They come in many different forms and lengths. Luckily, we have regular expressions on our side so we should be able to differentiate between good and bad email addresses. Before we look at the function we will use to validate email addresses, let's take a look at some common forms of them so we know what we are dealing with.

    name@somwhere.com
    first.last@somewhere.com
    first.last@place.someplace.us
    my_name@me.info
    me.something@somewhere.co.uk

    As you can see, email addresses can come in all shapes and sizes. Now, let's look at the function, and then we will examine the regular expression piece by piece.

    <?php
    function checkEmail($email) {
      
    $pattern "/^[A-z0-9\._-]+"
             
    "@"
             
    "[A-z0-9][A-z0-9-]*"
             
    "(\.[A-z0-9_-]+)*"
             
    "\.([A-z]{2,6})$/";
      return 
    preg_match ($pattern$email);
    }
    ?>

    Now, let's take a closer look at the pattern line by line. The first line specifies the match should begin at the start of the string. Then, it matches any alphabetic character, any digit, a period, underscore, or a hyphen. These characters must occur at least one time, but may appear many times. That takes care of the user name portion of the email address. The next line matches the literal @ character and nothing else. The third line starts matching the host name part of the email address. First, it matches any alphabetic character or digit exactly once. Then, any alphabetic character, any digit, or a hyphen can be matched zero or more times.

    The fourth line starts by matching a period. It then goes on to match any alphabetic character, a digit, underscore, or hyphen at least once. This entire fourth line can be matched zero or more times.

    The last line of the pattern matches a period followed by a set of any alphabetic characters. The set should have between two and six characters. This will match the top-level domain, i.e., .com, .net, .uk, etc. At the time of this writing, all top-level domains are between two and six characters in length. With the addition of new top-level domains, however, this could change. Simply adjusting the range will take care of this problem should it occur.

    More Miscellaneous Articles
    More By Matt Wade


       · 
       · Comments given fo title
       · sorry I ran this function and itdidn't work.
       · Remove the echo statement.
       · td.error {color:C03; font-weight:bold; }is incorrect, should be:td.error...
       · td.error {color: red; font-weight:bold; }
       · :)
       · I dont know how this is supposed to work but it doesnt..I can get the spell...
       · HOLY CRAP! I have been stuck on this for about a week and have spent about 6-10...
     

    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 1 hosted by Hostway
    Stay green...Green IT