Commit d1be768b authored by Dries's avatar Dries

- Moved the logic of email validation from user_validate_mail to a new function

  in common.inc.  Modified patch from Gerhard.
parent 8e9d557a
...@@ -255,6 +255,26 @@ function table($header, $rows) { ...@@ -255,6 +255,26 @@ function table($header, $rows) {
return $output; return $output;
} }
/**
* Verify the syntax of the given e-mail address. Empty e-mail addresses
* are allowed. See RFC 2822 for details.
*
* @param $mail a email address
*/
function validate_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}';
if (preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail)) {
return 1;
}
else {
return 0;
}
}
/** /**
* Format a single result entry of a search query: * Format a single result entry of a search query:
* *
......
...@@ -182,17 +182,7 @@ function user_validate_name($name) { ...@@ -182,17 +182,7 @@ function user_validate_name($name) {
function user_validate_mail($mail) { function user_validate_mail($mail) {
/* if ($mail && !validate_email_address($mail)) {
** Verify the syntax of the given e-mail address. Empty e-mail addresses
** allowed. See RFC 2822 for details.
*/
$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}';
if ($mail && !preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail)) {
return t("The e-mail address '%mail' is not valid.", array("%mail" => $mail)); return t("The e-mail address '%mail' is not valid.", array("%mail" => $mail));
} }
} }
......
...@@ -182,17 +182,7 @@ function user_validate_name($name) { ...@@ -182,17 +182,7 @@ function user_validate_name($name) {
function user_validate_mail($mail) { function user_validate_mail($mail) {
/* if ($mail && !validate_email_address($mail)) {
** Verify the syntax of the given e-mail address. Empty e-mail addresses
** allowed. See RFC 2822 for details.
*/
$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}';
if ($mail && !preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail)) {
return t("The e-mail address '%mail' is not valid.", array("%mail" => $mail)); return t("The e-mail address '%mail' is not valid.", array("%mail" => $mail));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment