Regular Expression Email Address Validation in PHP

email address validator function in php - validates email address by using regular expression

function-email-address-validator.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>email address validator function in php - validates email address by using regular expression</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Md Iqbal Hosan">
  <meta name="title" content="email address validator function in php - validates email address by using regular expression">
  <meta name="keywords" content="php, example, code, class, function, validates email address, regular expression">
  <meta name="description" content="email address validator function in php - validates email address by using regular expression">
  <style>
   h2, h3{background:#bbb; color:#000078;}
   h2{ padding:3px; margin:3px; font-size:21px;}
   h3{ padding:2px; margin:2px; font-size:18px;}
   p{ padding:3px; margin:3px;}
   body{ background:#FFFFFc;}
  </style>
 </head>
 <body>
  <h2>email address validator function in php - validates email address by using regular expression</h2>
  <pre>
   <?php
    /*
     -----------------------------------------------------------------------------------------
     let us make the function by using regular expression
     
     where
     
     1. ValidateEmailAddress is the function definition
     2. EmailAddress is the email address to be validated given by function call
     3. this function return true if the given email address is valid
      unless otherwise it will return false.
     -----------------------------------------------------------------------------------------
    */
    function ValidateEmailAddress($EmailAddress) 
    {
     $ValidEmail = true;
     if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $EmailAddress)) $ValidEmail = false;
     return $ValidEmail;
    }
    /*
     --------------------------------------------------------------------------------------
     now if is time to fire up the function and check whether the given email address is
     valid or not.
     --------------------------------------------------------------------------------------
    */
    $givenEmailAddress = "iqbalhosan@gmail.com";
    echo "<h3>parameter supplied to the ValidateEmailAddress() function</h3>";
    print "<p>$"."givenEmailAddress = ".$givenEmailAddress."</p>";

    $isValidEmailAddress = ValidateEmailAddress($givenEmailAddress);
    if($isValidEmailAddress)
    {
     echo "<p>Yes, it's a valid email address</p>";
    }
    else
    {
     echo "<p>No, it's not a valid email address</p>";
    }
    /*
     --------------------------------------------------------------------------------------
     you can dynamically change the value of $givenEmailAddress to get the desire result
     --------------------------------------------------------------------------------------
     
    */
     print "this post is written by the inspireation <a href='http://www.blogger.com/profile/00916064391343806858'>Tigeranwar</a>";
   ?>
  </pre>
 </body>
</html>

email address validator function in php - validates email address by using regular expression - output in the browser

 

Related Tutorial Examples

  1. Trace Visitor's IP Address PHP Example
  2. Trace Visitor's Browser & Operating System Information
  3. SERVER IP Address? - HTTP HOST PHP Server Variable Example
  4. SERVER ADMIN? - HTTP HOST PHP Server Variable Example
  5. Request Information? - REQUEST URI PHP Server Variable Example
  6. Referer Website Information? - HTTP REFERER PHP Server Variable Example
  7. 19 Examples to Learn MySQL
  8. 20 steps to make CakePHP Blog Project
  9. 28 Basic Tutorials to Learn Oracle
  10. preg_grep() Regular Expression PHP Example

1 comment:

leave your comments here..