samScripts.com
[Home] [My Scripts] [Contact] [Business Card Designer] [Donate] [$8.95 Domain Names]

Home > Scripts > Email address validation function

Email address validation function

... feel free to use this script for whatever you like.

Email address validation function

Simple function to validate email addresses.

Description:

This function just checks to see if an email address is syntactically correct. It doesn't verify that the address actually exists.

I didn't create this myself, but found it on the net ages ago.

Usage:

<?
if( validate_email($email) == true ){
   echo
"Yay! $email is valid!";
}else{
   echo
"Sorry, $email is not a valid email address.";
}
?>



<?php

function validate_email($email){
   if (
eregi("(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)", $email) ||
      !
eregi ("^.+\@(\[?)[-_a-zA-Z0-9\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$", $email)) {
      return(
false);
   } else {
      list(
$user, $domain) = explode("@", $email);
      if ((!
eregi("^[_a-zA-Z0-9\.\-]+$", $user)) ||
         (!
eregi("^[_a-zA-Z0-9\.\-]+$", $domain))) {
         return
false;
      } else {
         return(
true);
      }
   }
}

?>


[Back] [Top] [Forward]

Powered by php, mySql.

Request processed in 0.00 seconds on Wednesday 26th September 2012 23:43:14.

©2002 Sam Yapp

What do you think of my resume wizard site? All nicely written in php :)