First of all: thanks for that very useful module.
When using valid_email_address(), the following email shows a valid one: myname@gm
It seems that valid_email_address() return true when 2 characters are set after @
Hence I'd suggest to use the following regex rule instead of Drupal's valid_email_address().
That way, the module will show a yes/no check only when the email is actually valid.
function _check_email_validity($address)
{
$syntaxe='#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#';
if(preg_match($syntaxe,$address))
return true;
else
return false;
}Laurent
Comments
Comment #1
andrew m riley commentedHi Laurent, glad you like the module. I've toyed around with doing something similar but ended up going with what Drupal uses for the verification since that is technically what Drupal will allow. It's not great but I'm trying to keep it in line with core since this module really isn't a validation module, it is just to give the user some immediate feedback. Regexes to test an email address will always have shortcomings :(
Since the Drupal method is very open I made it so the script will not report an error until Drupal thinks that it is at least a valid email address. If it doesn't, the Ok or Not Ok message will not display. Based on some of the comments there are some others working on full validation modules. I am aiming to tie in with those in the future.
RFC 2822 regex from http://www.regular-expressions.info/email.html
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
Comment #2
andrew m riley commentedActually, I've thought about it more and I've changed my mind. I'll make this an option for admins. They can decide which method they want to use.
Comment #3
agence web coheractio commentedMany thanks Andrew.
Comment #4
andrew m riley commentedAs part of https://www.drupal.org/node/1513156 I'm adding hooks so glue modules or other modules can add in whatever checks they want.