Closed (won't fix)
Project:
Drupal core
Version:
7.x-dev
Component:
base system
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
30 May 2010 at 20:58 UTC
Updated:
25 Oct 2014 at 18:36 UTC
Jump to comment: Most recent
the function valid_email_address($mail)
<?php
function valid_email_address($mail) {
$user = '[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\']+';
$domain = '(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.?)+';
$ipv4 = '[0-9]{1,3}(\.[0-9]{1,3}){3}';
$ipv6 = '[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7}';
return preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail);
}
?>
does not tot get all the (in)valid email addresses. a better reg expression can be found on http://fightingforalostcause.net/misc/2006/compare-email-regex.php
/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i
Is this somthing we can use and put in?
Comments
Comment #1
mfer commentedDrupal 7 uses filter_var() to handle the regex and there are tests in core.
But, D7 requires php 5.2+. The regex used by filter_var() before php 5.2.14 or in the 5.3 branch before 5.3.3 would fail tests if we had them in core. Yeah, it looks like valid_email_address change went in without tests (I wrote it so you can blame me).
I'm thinking we test for the PHP version and if it has the bad regex we use the one straight out of PHP head. You can see the comment block, regex, and change at http://svn.php.net/viewvc/php/php-src/tags/php_5_2_14/ext/filter/logical...
And we should add tests. I'll add this to my todo list unless someone else wants it.
Oh, and I'm putting this here because the regex in PHP head is based on the referenced article. We just have some other versions to deal with.
One note, what is in PHP and what we are using disallows addresses like foo@localhost. There are considered invalid per the spec. This is good for Drupal because we expect email addresses to be valid and routable.
Comment #2
markie commentedI have problem with valid_email_address(). Nothing personal, but one of my clients has an underscore in their domain name. This is not validating using the current D7 install. I had to make the following change to webform.module:
Comment #3
bertboerland commentedactually user@localhost IS a valid email address, see http://drupal.org/node/308138#comment-1014414
Comment #4
pepekovac commentedMy problem with valid_email_address() (Drupal 6.24):
Do not accept as valid e-mail this format: "user@subdomain.domain-name.xy" (eg. foo@mail.t-com.sk).
My way to fix:
Comment #5
amourowThanks pepekovac,
this is really a problem, in this case when the hyphen "-" in the second place can never be sent.
Comment #6
fonant commentedPepekovac's fix works for person@school.w-sussex.sch.uk too, but it allows some invalid addresses through, such as test@school.-sussex.sch.uk
Comment #7
fonant commentedThis is fixed for Drupal 6 in version 6.25 with a roll-back for the broken fix mentioned here: #12274: Do not validate email addresses with trailing periods
Comment #8
plazik commentedD7 doesn't validate email with two or more points like "test..test@test.com". This is a real problem. I upgraded site from 6 to 7 and some users can't change profile settings because email isn't validate.
Comment #9
traviscarden commentedObsolete as of #308138: Make valid_email_address() support IDNs.