Email Validator

Email ValidatorA simple email validator

1. Copy this into your PHP Script

//-----------------------
// Email Checker
//-----------------------
function check_email_address($email) {

  if (!ereg("[^@]{1,64}@[^@]{1,255}", $email)) {

    return false;
  }

  $email_array = explode("@", $email);
  $local_array = explode(".", $email_array[0]);
  for ($i = 0; $i < sizeof($local_array); $i++) {
     if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~.-]{0,63})|("[^(|")]{0,62}"))$", $local_array[$i])) {
      return false;
    }
  }  
  if (!ereg("^[?[0-9.]+]?$", $email_array[1])) { 
    $domain_array = explode(".", $email_array[1]);
    if (sizeof($domain_array) < 2) {
        return false; 
    }
    for ($i = 0; $i < sizeof($domain_array); $i++) {
      if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
        return false;
      }
    }
  }
  return true;
}

2. This is an example of it in use

<?php
$email  = $_POST['email'];

if (check_email_address($email)) {

if (empty($email))
{
 echo "Error: Please Enter the Authors Email Address";
 exit;


else 
{
 echo "Error: '$email' is Not a Valid Email Address";
 exit;
}

}
//rest of the code here
?>

Related Articles

  • PHP:Form Series: Validators & Client-side Validation
    This tutorial is really helpful to those of us who are a little intimidated by PHP:form. All of those hard to answer questions are easily explained in this simple to use educational web page. Hope you enjoy!
  • Why Validate Your HTML?
    Creating Valid HTML Documents Means Cleaner Code and Easier Maintenance. Ill be the first one to let you in on a secret: building Web pages isnt hard. With the software that is available now, you can write your Web page and have it up and viewable in half an hour...
  • Cross Browser Compatibility
    If you want everybody to have access to your site, youd better make sure it is recognized by all existing browsers. These useful tips will help you check yourself.
  • What does W3C Validation Stand For?
    This article will explain this to you if your website is W3C Validated and what W3C stands for and means.
  • CSS Validation and HTML
    HTML validation and CSS validation are controversial issues with some people. This article discusses some of the issues that have come increasingly to the fore in web development. The article will also provide a practical method that overworked webmasters can use to improve their website.
  • 7 Benefits of HTML Validation
    You may not bother with html validation or writing simple and clean code when designing your web site. Later you may find your site is slow loading, appears incorrectly in the main browsers and does not rank well for the major search engines...
  • The Power of Email Marketing
    Did you know that by just sending an email you can create cash on demand?
  • Why You Should Add Email Service to Your Website
    The answer is quite simple - Email is the
  • How To Properly Submit Your Website To Directories
    Having a top placement on a search engine and enjoying the traffic that comes with a top ranking is dependent on many things. Certainly at the top of that list is having as many links and quality links pointing to your site...
  • Simple Contact Form
    Learn how to write a clean and easy contact form for your site.

Contact Web Design Outsource and get started today

Need Website Designing, Development, Redesigning, Maintenance and SEO services or help growing your company's web presence? Request a free Quote Now.