Search:
Main Menu
Login | RSS |

Quick PHP Code Tips and Examples

PHP Programming Tips, Tutorials and Source Code Examples for newbie

PHP Snippets : Email Validation Source Code

March 8th, 2007 by Jon Moffet

Here's a simple function to validate email in your PHP scripts.

To use it just call isValidateAddress("email@example.com"). The function returns 'true' if the email is valid and 'false' otherwise.

PHP:
  1. <?php function isValidAddress( $email, $check = false )
  2. {
  3.   ##############################
  4.   # PHP Email Address Validator
  5.   # (C) Derrick Pallas
  6.  
  7.   # Authors: Derrick Pallas
  8.   # Website: http://derrick.pallas.us/email-validator/
  9.   # License: Academic Free License 3.0
  10.   # Version: 2006-12-01a
  11.  
  12.   if (!ereg(''
  13.       . '^'
  14.       . '[-!#$%&\'*+/0-9=?A-Z^_a-z{|}~]'
  15.       . '(\\.?[-!#$%&\'*+/0-9=?A-Z^_a-z{|}~])*'
  16.       . '@'
  17.       . '[a-zA-Z](-?[a-zA-Z0-9])*'
  18.       . '(\\.[a-zA-Z](-?[a-zA-Z0-9])*)+'
  19.       . '$'
  20.       , $email
  21.       )    ) return false;
  22.   list( $local, $domain ) = split( "@", $email, 2 );
  23.   if ( strlen($local)> 64 || strlen($domain)> 255 ) return false;
  24.   if ( $check && !gethostbynamel( $domain ) ) return false;
  25.   return true;
  26.  
  27.   # END
  28.   ######
  29. }

Tags: , , , , ,

Bookmark Post:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • NewsVine
  • Reddit
  • Netvouz
  • Spurl
  • Furl
  • digg
  • YahooMyWeb
  • del.icio.us

Posted in Uncategorized |

Related Posts

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.