function valid_email_address

7.x common.inc valid_email_address($mail)
6.x common.inc valid_email_address($mail)

Verifies the syntax of the given e-mail address.

See RFC 5322 for details.

Parameters

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

Return value

1 if the email address is valid, 0 if it is invalid or empty, and FALSE if there is an input error (such as passing in an array instead of a string).

Related topics

7 calls to valid_email_address()
comment_validate in drupal-6.x/modules/comment/comment.module
Validate comment data.
contact_admin_edit_validate in drupal-6.x/modules/contact/contact.admin.inc
Validate the contact category edit page form submission.
contact_mail_page_validate in drupal-6.x/modules/contact/contact.pages.inc
Validate the site-wide contact page form submission.
contact_user_page in drupal-6.x/modules/contact/contact.pages.inc
Personal contact page.
system_send_email_action_validate in drupal-6.x/modules/system/system.module
Validate system_send_email_action form submissions.

... See full list

File

drupal-6.x/includes/common.inc, line 1002
Common functions that many Drupal modules will need to reference.

Code

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);
}