8.5.x common.inc valid_email_address($mail)
8.0.x common.inc valid_email_address($mail)
8.1.x common.inc valid_email_address($mail)
8.2.x common.inc valid_email_address($mail)
8.3.x common.inc valid_email_address($mail)
8.4.x common.inc valid_email_address($mail)
8.6.x common.inc valid_email_address($mail)
4.6.x common.inc valid_email_address($mail)
4.7.x common.inc valid_email_address($mail)
5.x common.inc valid_email_address($mail)
6.x common.inc valid_email_address($mail)
7.x common.inc valid_email_address($mail)

Verifies the syntax of the given e-mail address.

This uses the PHP e-mail validation filter.


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

Return value

TRUE if the address is in a valid format.

Related topics


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


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


geerlingguy’s picture

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.

BrockBoland’s picture

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.


  • PHP 5.2 (potentially only up to 5.2.8): valid_email_address('john@example') returns FALSE
  • PHP 5.3: valid_email_address('john@example') returns TRUE

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

nerdoc’s picture

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.

kingandy’s picture

I ran this address through an online validator and it rejected it based on RFC 5322 (which claims to obsolete RFC 2822, and presumably is what FILTER_VALIDATE_EMAIL runs off). According to this RFC, "Neither part of the address may end with a dot".

Even if it wasn't, though, this would be something to raise to PHP rather than Drupal...

sardbaba’s picture

This https://3v4l.org/UgBPI can be useful to understand that the usage of the filter FILTER_VALIDATE_EMAIL it is not consistent.