From 25cdd980fcacf168effe1c977f2844ae32112810 Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Thu, 3 Jul 2014 23:19:30 +0000 Subject: [PATCH] Added valid_email() function for verifying email address syntax. --- resources/functions.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/resources/functions.php b/resources/functions.php index b37ceea854..ba460c1a31 100644 --- a/resources/functions.php +++ b/resources/functions.php @@ -950,4 +950,16 @@ function number_pad($number,$n) { return str_pad((int) $number,$n,"0",STR_PAD_LEFT); } +// validate email address syntax +if(!function_exists('validate_email')) { + function valid_email($email) { + $regex = '/^[A-z0-9][\w.-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}$/'; + if ($email != "" && preg_match($regex, $email) == 0) { + return false; // email address does not have valid syntax + } + else { + return true; // email address has valid syntax + } + } +} ?>