[drupal-devel] [bug] other valid emails fail too

Dries drupal-devel at drupal.org
Sun Aug 14 10:21:27 UTC 2005

Issue status update for 
Post a follow up: 

 Project:      Drupal
 Version:      4.6.0
 Component:    base system
 Category:     bug reports
 Priority:     critical
 Assigned to:  CdnStrangequark
 Reported by:  jwells
 Updated by:   Dries
 Status:       patch (code needs review)

Using Drupal HEAD, the following code returns 3 x TRUE:

print valid_email_address("first.last at somewhere.com");
print valid_email_address("first.last at sub.somewhere.com");
print valid_email_address("first.last at sub.sub.somewhere.com");
Looking at the code, valid_email_address() in HEAD is no different from
the one in DRUPAL-4-6.

1.190        (dries    13-Apr-03): function valid_email_address($mail)
1.185        (dries    28-Mar-03):   $user =
1.350        (dries    24-May-04):   $domain =
1.185        (dries    28-Mar-03):   $ipv4 =
1.185        (dries    28-Mar-03):   $ipv6 =
1.185        (dries    28-Mar-03): 
1.278        (dries    13-Dec-03):   return
preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail);
1.231        (dries    16-Jul-03): }

In short: I can't reproduce this problem.


Previous comments:

Fri, 22 Apr 2005 05:00:42 +0000 : jwells

When attemping to use a sub-domain email address for a new account, it
won't pass the syntax test. We know that its really the base - but I'm
sure a lot of end uers don't know.

newaccount at research.drupal.org - this type of address will fail, though
it is actually legal


Tue, 10 May 2005 15:00:25 +0000 : CdnStrangequark

Not just sub-domain emails. If you have an email address of the form:
"first.last at somewhere.com" it will also fail even though this is
perfectly valid.


Tue, 10 May 2005 16:30:58 +0000 : CdnStrangequark

After attempting to enter more emails on one of my new sites, I also
discovered that the validation fails in yet more perfectly valid cases.
For example: "myemail at somewhere.xx" where xx is the country domain code.
(like .ca, or .us).  Not all country codes are accepted.

Here is a replacement I made for the code in common.inc:
*valid_email_address($mail)* that works just great:

$user = "[-a-z0-9!#$%&'*+/=?^_`{|}~]";
$domain = "([a-z]([-a-z0-9]*[a-z0-9]+)?)";
$regex = "^$user+(\.$user+)*@($domain{1,63}\.)+$domain{2,63}$";
//Return a 1 or 0 to mimic results of preg_match
if (eregi($regex, $mail)) {
  return 1;
} else {
  return 0;

The only thing this doesn't do is allow for "user at localhost" but does
anyone really do that anyway? The code could be modified to do it
through an alternate check on $domain though.

PS: I left this post's status as active and unassigned cause I'm kinda
new here and don't know the process for submitting patches and bug
fixes. Hope someone can put this code in the core though cause I'm sure
we're not the only ones who have run into the problem.


Tue, 10 May 2005 21:07:29 +0000 : killes at www.drop.org

Attachment: http://drupal.org/files/issues/valid_email.patch (1.31 KB)

Our intrepid Debian developer has cooked up a patch. It is based on RFC
2822 but it needs testing.


Tue, 10 May 2005 21:24:54 +0000 : Cvbge

Please add a button 'I know my email is good, accept it!' that would be
displayed when email is found invalid.

More information about the drupal-devel mailing list