View Single Post
  #2  
Old 08-08-2006, 02:52 PM
gilchrist gilchrist is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
gilchrist is on a distinguished road
Default

TBH, its only really worthwhile checking for the existance of the '@' symbol - if someone wants to give a bad email, they really will, evne if it 'should' exist.

Anyway, something like this ought to hold true for any (current) email addresses:

PHP Code:
function legal_email($email)
{
return ( preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email)) ? True : False;
}


But its not pretty to look at, far simpler to use something like this (ok, it only shows they're trying to give an email, but thats really the best you should hope for)

PHP Code:
function legal_email($email)
{
return (strchr($email, '@') !== False) ? True : False;
}



as to bugs in your function, you don't need commas between a-z,0-9 etc. Beyond that, it may be that POSIX won't work with it [this is not true, -- 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
  #2  
Old 08-08-2006, 02:52 PM
gilchrist gilchrist is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
gilchrist is on a distinguished road
Default

TBH, its only really worthwhile checking for the existance of the '@' symbol - if someone wants to give a bad email, they really will, evne if it 'should' exist.

Anyway, something like this ought to hold true for any (current) email addresses:

PHP Code:
function legal_email($email)
{
return ( preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email)) ? True : False;
}


But its not pretty to look at, far simpler to use something like this (ok, it only shows they're trying to give an email, but thats really the best you should hope for)

PHP Code:
function legal_email($email)
{
return (strchr($email, '@') !== False) ? True : False;
}



as to bugs in your function, you don't need commas between a-z,0-9 etc. Beyond that, it may be that POSIX won't work with it [this is not true, -- 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