valid_email_address

Versions
4.6 – 7
valid_email_address($mail)

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

comment_validate in modules/comment.module
contact_admin_edit_validate in modules/contact.module
Validate the contact category edit page form submission.
contact_mail_page_validate in modules/contact.module
Validate the site-wide contact page form submission.
contact_mail_user in modules/contact.module
Personal contact page.
user_validate_mail in modules/user.module

Code

includes/common.inc, line 651

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

The return valus is not a boolean

hadubard - Sat, 2009-08-29 12:40

The documented return value is not strictly a boolean. It is either 1 for a valid adress or 0 for an invalid one. So don't test with a construct like:

<?php
 
if (valid_email_address($mail) === TRUE) {
   
// ...
 
}
?>

because this will fail!

See: http://drupal.org/node/505730

Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.