diff --git a/modules/user.module b/modules/user.module
index cb170f5795488429e4c38acf0cdfd51e29b39373..6cb02d04eb4830ca849d26b87034159436d6b0c3 100644
--- a/modules/user.module
+++ b/modules/user.module
@@ -187,7 +187,12 @@ function user_validate_mail($mail) {
   ** allowed.
   */
 
-  if ($mail && !eregi("^[0-9a-z_\.-]+@(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2,})$", $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 ($mail && !preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $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 cb170f5795488429e4c38acf0cdfd51e29b39373..6cb02d04eb4830ca849d26b87034159436d6b0c3 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -187,7 +187,12 @@ function user_validate_mail($mail) {
   ** allowed.
   */
 
-  if ($mail && !eregi("^[0-9a-z_\.-]+@(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2,})$", $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 ($mail && !preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail)) {
     return t("The e-mail address '%mail' is not valid.", array("%mail" => $mail));
   }
 }