<?Php
function check_email_address($email) {
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
}
?>
Using the function above is relatively simple, as you can see:
<?Php
if (check_email_address($email)) {
echo $email . ' is a valid email address.';
} else {
echo $email . ' is not a valid email address.';
}
?>
Tuesday, July 29, 2008
PHP Email Address Validation
Labels:
Email Address,
Email Validator,
Php Codes,
Php Email,
Php Validators
Subscribe to:
Post Comments (Atom)
3 comments:
oei526v-clbw8kc-tw6q32f3-0 http://urlser.com/?aBCA5#1
car insurance
[url=http://urlser.com/?nm4rK#3]cheap auto insurance[/url]
[url]http://urlser.com/?boo2X#4[/url]
[http://free-poker-mo.lookera.net#5 free poker]
"progressive insurance":http://urlser.com/?5Nnno#6
[LINK http://urlser.com/?DYEVZ#7]insurance quotes[/LINK]
[img]http://victor.freewebhostingpro.com/1.php[/img]
ccmc974-xz4420c-tw6q32f3-0 http://roulette-mo.lookera.net#1
auto insurance quotes
[url=http://urlser.com/?nm4rK#3]cheap auto insurance[/url]
[url]http://urlser.com/?e64r6#4[/url]
[http://urlser.com/?DYEVZ#5 insurance quotes]
"life insurance":http://urlser.com/?boo2X#6
[LINK http://urlser.com/?DYEVZ#7]insurance quotes[/LINK]
[img]http://victor.freewebhostingpro.com/1.php[/img]
aon4d2d-vbx4g0a-tw6q32f3-0 texas holdem
http://urlser.com/?DYEVZ#1
[url=http://urlser.com/?qbKvI#3]health insurance[/url]
[url]http://urlser.com/?3kTmj#4[/url]
[http://online-poker-mo.lookera.net#5 online poker]
"insurance":http://urlser.com/?xFj4E#6
[LINK http://free-poker-mo.lookera.net#7]free poker[/LINK]
[img]http://victor.freewebhostingpro.com/1.php[/img]
Post a Comment