From d1be768b28b17315c7785cbd1c7769bdf64665c7 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 28 Mar 2003 10:55:27 +0000 Subject: - Moved the logic of email validation from user_validate_mail to a new function in common.inc. Modified patch from Gerhard. --- includes/common.inc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'includes/common.inc') diff --git a/includes/common.inc b/includes/common.inc index d946e64ba..306433e60 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -255,6 +255,26 @@ function table($header, $rows) { 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: * -- cgit v1.2.3