Regular expression in php of email address
Posted: Tue Jan 09, 2007 11:13 pm
i need regular expression in php for validation of email field.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
I guess, you may find hundreds of regular expression dealing with email validations on Regex discussionnasir wrote:i need regular expression in php for validation of email field.
Code: Select all
ereg("[_a-zA-Z0-9.\'-]*@[_a-zA-Z0-9-]*\.[_a-zA-Z0-9-]*", $email)Code: Select all
<?php
$email = "a.b@c.com";
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
echo "The e-mail was not valid";
} else {
echo "The e-mail was valid";
}
?>Code: Select all
The e-mail was validCode: Select all
The e-mail was not validBut the extra info like .com or .net or some country code .com.np is missing. That is why it's invalid. Isn't it feyd ? I might be wrong.feyd wrote:Too bad a.b@cnet is a valid email address
Unfortunately, you are wrong.dibyendrah wrote:But the extra info like .com or .net or some country code .com.np is missing. That is why it's invalid. Isn't it feyd ? I might be wrong.
validateEmailFormat() given in your link was preety complex just to validate email address. I think that kind of email exist only on intranet. root@localhost or someuser@some.ip.address .feyd wrote:Unfortunately, you are wrong.dibyendrah wrote:But the extra info like .com or .net or some country code .com.np is missing. That is why it's invalid. Isn't it feyd ? I might be wrong.
The RFC that governs email addresses does not require a dot to appear in the domain part.
validateEmailFormat()