Community Documentation

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 functions call valid_email_address()

comment_form_validate in modules/comment/comment.module
Validate comment form submissions.
contact_category_edit_form_validate in modules/contact/contact.admin.inc
Form validation handler for contact_category_edit_form().
contact_personal_form_validate in modules/contact/contact.pages.inc
Form validation handler for contact_personal_form().
contact_site_form_validate in modules/contact/contact.pages.inc
Form validation handler for contact_site_form().
system_send_email_action_validate in modules/system/system.module
Validate system_send_email_action form submissions.
update_settings_validate in modules/update/update.settings.inc
Validation callback for the settings form.
user_validate_mail in modules/user/user.module
Validates a user's email address.
_openid_invalid_openid_transition in modules/openid/openid.inc
Provides transition for accounts with possibly invalid OpenID identifiers in authmap.

File

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

Code

<?php
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.

Login or register to post comments