[Fusionforge-commits] r14104 - branches/Branch_5_1/src/common/include

Olivier Berger olberger at fusionforge.org
Fri Aug 12 12:53:25 CEST 2011


Author: olberger
Date: 2011-08-12 12:53:25 +0200 (Fri, 12 Aug 2011)
New Revision: 14104

Modified:
   branches/Branch_5_1/src/common/include/utils.php
Log:
Use filter_var with FILTER_VALIDATE_EMAIL whenever possible instead of reinventing a local wheel

Modified: branches/Branch_5_1/src/common/include/utils.php
===================================================================
--- branches/Branch_5_1/src/common/include/utils.php	2011-08-12 10:53:20 UTC (rev 14103)
+++ branches/Branch_5_1/src/common/include/utils.php	2011-08-12 10:53:25 UTC (rev 14104)
@@ -818,11 +818,21 @@
  *
  */
 function validate_email ($address) {
-	if ( preg_match( "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+$/", $address) ) {
-		return true;
-	} else {
-		return false;
+	if (version_compare(PHP_VERSION, '5.2.0', '>=')) {
+		if ( filter_var($address, FILTER_VALIDATE_EMAIL) ) {
+			return true;
+		}
+		else {
+			return false;
+		}
 	}
+	else {
+		if ( preg_match( "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+$/", $address) ) {
+			return true;
+		} else {
+			return false;
+		}
+	}
 }
 
 /**




More information about the Fusionforge-commits mailing list