Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to validate email 2

Status
Not open for further replies.

Sina

Technical User
Jan 2, 2001
309
0
0
CA
Does any one have a piece of code that would properly validate email addresses?

Thanks for the help in advance.
 
Here is a little snippet of code that you can use:

[tt]

<?php
function is_email_valid($email) {
if(eregi(&quot;^[a-zA-Z0-9._-]+@([a-zA-Z0-9._-]+\.)+([a-zA-Z]){2,3}$&quot;, $email)) return TRUE;
else return FALSE;
}
?>
[/tt]

And you use the function such as so:

[tt]
$email = &quot;me@zend.com&quot;;
if (is_email_valid($email)) print &quot;E-Mail OK&quot;;
else print &quot;E-Mail not valid&quot;;
[/tt]

Hope this helps.

-Vic vic cherubini
malice365@hotmail.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
heres a regular expression that will do the trick

function emailvalidator($emailaddress) {

$result = ereg(&quot;^[^@ ]+@ ]+\.[^@ \.]+$&quot;, $emailaddress, $trash);

if ($result) :

##email is good

else :

##email is bad

endif;

return $something;

}

Andres Jugnarain
Wireless Editor
 
Thank you both for the code.

Thanks much for taking the time.

Regards,
Sina
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top