Page 1 of 1
Verifying Email Addresses
Posted: Fri Aug 09, 2002 12:36 pm
by JPlush76
Do you generally as a rule of thumb verify your forms with ereg expression checking or do you actually go out there and verify its a working email address through socket checking?
I've been getting some faulty email addresses lately and I'd like to tighten that up a bit.
I've seen a few posts on here with samples but didn't know if there was a general rule of thumb. thanks!
Posted: Fri Aug 09, 2002 12:58 pm
by darkshine
that one should be ok:
^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
yo works ereg or preg_match_all
Posted: Fri Aug 09, 2002 1:01 pm
by JPlush76
I was going to start using :
Code: Select all
function emailcheck($intext){
$theresults = ereg("^ї^@ ]+@ї^@ ]+\.ї^@ \.]+$", $intext, $trashed);
if($theresults) { $isamatch = "yes"; } else { $isamatch = "no"; }
return $isamatch;
}
if(emailcheck($email) == 'yes'){
echo "EMAIL ADDRESS MATCHED";
} else {
echo "EMAIL NO GOOD";
}
I guess thats not a great checker, but what I've been seeing is alot of:
johnaol.com
or just johm
or john@aol
things like that
Posted: Fri Aug 09, 2002 3:49 pm
by Polar
HI !
or may be
/^[A-z0-9_\-]+(\.[A-z0-9_\-]+)*@[A-z0-9_]+((\-|\.)[A-z0-9_]+)*\.[A-z]{2,}$/
or better
/^[A-z0-9_\-]+(([^(\s\"\(\)<>@,;:\\<>\.\[\])]|\.)[A-z0-9_\-]+)*@[A-z0-9_]+((\-|\.)[A-z0-9_]+)*\.[A-z]{2,}$/
?

Posted: Fri Aug 09, 2002 4:03 pm
by MattF
Rather than returning yes or no use true or false, try this out for size (with whichever regular expression you prefer):
Code: Select all
function emailcheck($intext){
if(ereg("^ї^@ ]+@ї^@ ]+\.ї^@ \.]+$", $intext, $trashed)) {
return true;
} else {
return false;
}
}
if(emailcheck($email)){
echo "EMAIL ADDRESS MATCHED";
} else {
echo "EMAIL NO GOOD";
}
I cut out several unneeded strings there and saved lots of lines

Posted: Fri Aug 09, 2002 4:11 pm
by JPlush76
hey matt thanks for the tip!
how would I code the if statement if I wanted to check if emailcheck = false?
Code: Select all
if(emailcheck($email) == 0){
echo "BAD EMAIL, YOU GO FIX NOW ";
exit;
}
Posted: Fri Aug 09, 2002 4:21 pm
by JPlush76
hey Polar, what is that extra ereg code checking for?

Posted: Fri Aug 09, 2002 4:59 pm
by Polar
Hi !
1. disallowed symbols
"<" , ">" , "(" , ")" , "[" , "]" , "\" , "," , ";" , ":" , "@" , """ and whitespace \s (tab, newline and etc)
it is rule
2. address must start from "A-z0-9_" or "-"
it is rule
3. in first part of address (before @) all allowed symbols othere then "A-z0-9_" and "-" must be followed by "A-z0-9_" or "-"
it is recommendation
4. second part of address (domain after @) must start from "A-z0-9"
it is rule
5. in second part of address there may be only "A-z0-9_" symbols with "." and "-" followed by "A-z0-9"
it is recommendation
6. in the end of addres must be dot with and at least 2 letters
it is a rule

Posted: Fri Aug 09, 2002 5:05 pm
by JPlush76
ah thanks polar!