validating the syntax of an email address
Posted: Tue Aug 08, 2006 5:01 am
Hi people
can someone supply with a PHP code that checks whether a given PHP string
constitutes a legal email address in terms of the syntax?
I am sure regular expressions are the way to go.
I found the following solution:
But when I pass the value 'john@yahoo.com' it says that the email address is NOT valid.
Does that sound right?
Can anyone see the bug in the function?
regards
can someone supply with a PHP code that checks whether a given PHP string
constitutes a legal email address in terms of the syntax?
I am sure regular expressions are the way to go.
I found the following solution:
Code: Select all
function isValidEmailSyntax($email) {
if(ereg("^([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])*$",$email)) {
return true;
} else {
return false;
}
}Does that sound right?
Can anyone see the bug in the function?
regards