You are here

function valid_email_address in Drupal 5

Same name and namespace in other branches
  1. 8 core/includes/common.inc \valid_email_address()
  2. 4 includes/common.inc \valid_email_address()
  3. 6 includes/common.inc \valid_email_address()
  4. 7 includes/common.inc \valid_email_address()

Verify 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

5 calls to valid_email_address()
comment_validate in modules/comment/comment.module
contact_admin_edit_validate in modules/contact/contact.module
Validate the contact category edit page form submission.
contact_mail_page_validate in modules/contact/contact.module
Validate the site-wide contact page form submission.
contact_user_page in modules/contact/contact.module
Personal contact page.
user_validate_mail in modules/user/user.module

File

includes/common.inc, line 909
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);
}