Regular expression in php of email address
Moderator: General Moderators
Regular expression in php of email address
i need regular expression in php for validation of email field.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
Re: Regular expression in php of email address
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.
viewforum.php?f=38
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
This is my first post on this forum, so please forgive me if this code doesnt turn out right...
This code wont accept anything unless it has exactly one @ character and at least one dot.
Dan.
Code: Select all
ereg("[_a-zA-Z0-9.\'-]*@[_a-zA-Z0-9-]*\.[_a-zA-Z0-9-]*", $email)Dan.
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
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 valid- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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()
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
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()
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact: