View Single Post
  #1  
Old 08-08-2006, 02:50 PM
nuwan nuwan is offline
Junior Member
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
nuwan is on a distinguished road
Default Validating the syntax of an email address

Hi there

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:

Hi
Hi

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;
}
}


But when I pass the value 'nuwan@yahoo.com' it says that the email address is NOT valid.
Does that sound right?
Can anyone see the bug in the function? -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  Webmaster Forums - View Single Post - Validating the syntax of an email address
View Single Post
  #1  
Old 08-08-2006, 02:50 PM
nuwan nuwan is offline
Junior Member
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
nuwan is on a distinguished road
Default Validating the syntax of an email address

Hi there

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:

Hi
Hi

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;
}
}


But when I pass the value 'nuwan@yahoo.com' it says that the email address is NOT valid.
Does that sound right?
Can anyone see the bug in the function? -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote