valid_email_address
Definition
valid_email_address($mail)
includes/common.inc, line 781
Description
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
| Name | Description |
|---|---|
| Input validation | Functions to validate user input. |
Code
<?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);
}
?> 