Function
From Haohappy ' S blog an email validation function
<?php
function Valid_email ($email) {
We check that there ' s one @ symbol, and that's 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;
}
?>