summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/common.inc20
-rw-r--r--modules/user.module12
-rw-r--r--modules/user/user.module12
3 files changed, 22 insertions, 22 deletions
diff --git a/includes/common.inc b/includes/common.inc
index d946e64ba..306433e60 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -256,6 +256,26 @@ function table($header, $rows) {
}
/**
+ * 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:
*
* @param $item a single search result as returned by <module>_search of type
diff --git a/modules/user.module b/modules/user.module
index 8dd81ae35..c656e683d 100644
--- a/modules/user.module
+++ b/modules/user.module
@@ -182,17 +182,7 @@ function user_validate_name($name) {
function user_validate_mail($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)) {
+ if ($mail && !validate_email_address($mail)) {
return t("The e-mail address '%mail' is not valid.", array("%mail" => $mail));
}
}
diff --git a/modules/user/user.module b/modules/user/user.module
index 8dd81ae35..c656e683d 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -182,17 +182,7 @@ function user_validate_name($name) {
function user_validate_mail($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)) {
+ if ($mail && !validate_email_address($mail)) {
return t("The e-mail address '%mail' is not valid.", array("%mail" => $mail));
}
}