valid_email_address

5 common.inc valid_email_address($mail)
6 common.inc valid_email_address($mail)
7 common.inc valid_email_address($mail)
8 common.inc valid_email_address($mail)

Verifies the syntax of the given e-mail address.

Empty e-mail addresses are allowed. See RFC 2822 for details.

Parameters

$mail: A string containing an e-mail address.

Return value

TRUE if the address is in a valid format.

Related topics

8 calls to valid_email_address()

File

includes/common.inc, line 1111
Common functions that many Drupal modules will need to reference.

Code

function valid_email_address($mail) {
  return (bool) filter_var($mail, FILTER_VALIDATE_EMAIL);
}

Comments

As is mentioned on the Drupal

As is mentioned on the Drupal 6 API docs page for this function, an email address in the form of username@domain (without a TLD, like .com, .org, or .net...) will be accepted as valid—on certain PHP installations...

I found that on my MAMP default install (PHP 5.2.17), the non-TLD email addresses returned a FALSE, while on one of my production servers (PHP 5.2.13), non-TLD addresses returned TRUE.

PHP 5.3

According to comments on the PHP docs about filters, this condition is only true beginning with PHP 5.3. There is also an issue in the Drupal queue wherein catch mentions upgrading to PHP 5.2.9+, so this may exist as far back as 5.2.9. Based on your testing, there may also be a configuration option in place, since one would expect it to return TRUE when running on either 5.2.13 or 5.2.17.

So:

This is not a bug, technically, but should be taken into account when making use of this function.

test.@example.com considered FALSE

not the dot at the end of "test." - this is a bug IMHO - this is a valid email address - I know 2 people that have an address with a dot at the end of ther $user part.

Login or register to post comments