| 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
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);
}
?> Login or register to post comments
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
TRUEwhen running on either 5.2.13 or 5.2.17.So:
valid_email_address('john@example')returnsFALSEvalid_email_address('john@example')returnsTRUEThis is not a bug, technically, but should be taken into account when making use of this function.