From 38b8884ea6d470cdf438983cc98acb61c2d8f8c3 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 12 Feb 2009 14:39:44 +0000 Subject: [PATCH] =?UTF-8?q?-=20checkEmail=20:=20Ajout=20de=20la=20possibil?= =?UTF-8?q?it=C3=A9=20de=20v=C3=A9rifier=20le=20nom=20de=20domaine=20par?= =?UTF-8?q?=20un=20=09ou=20plusieurs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trunk/includes/functions.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/trunk/includes/functions.php b/trunk/includes/functions.php index 19847293..cecd4ba9 100644 --- a/trunk/includes/functions.php +++ b/trunk/includes/functions.php @@ -316,19 +316,31 @@ function LSdebugDefined() { } function checkEmail($value,$domain=NULL,$checkDns=true) { - if (!$domain) { - $domain = '((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))'; - } - $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@'.$domain.'$/'; + $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/'; if (!preg_match($regex, $value)) { LSdebug('checkEmail : regex fail'); return false; } + $nd = explode('@', $value); + $nd=$nd[1]; + + if ($domain) { + if(is_array($domain)) { + if (!in_array($nd,$domain)) { + return false; + } + } + else { + if($nd!=$domain) { + return false; + } + } + } + if ($checkDns && function_exists('checkdnsrr')) { - $tokens = explode('@', $value); - if (!(checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A'))) { + if (!(checkdnsrr($nd, 'MX') || checkdnsrr($nd, 'A'))) { LSdebug('checkEmail : DNS fail'); return false; }