note 53677 rejected from function.preg-match by mazzanet

From: Date: Thu, 09 Jun 2005 05:30:58 +0000
Subject: note 53677 rejected from function.preg-match by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-90157@lists.php.net to get a copy of this message
Note Submitter: sunil_ssm at users dot sourceforge dot net ---- The following function validates an email address. Does a better job than most validate functions and with very minimal coding. ------------ function is_email($addr) { //Check for illegal sequences. //Note: I had to expand the variable '$illegal' to 2 DIFFERENT lines to allow this post. //php.net complains that this line is too long !!! $illegal = "/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|"; $illegal .= "(\.$)|(^\_)|(\_@)|(\-\-)|(\_\_)/"; //Check for proper format. $format = "/^([a-z0-9\\_\\.]+)@[a-z0-9\\-\\.]+\\.([a-z]+)$/i"; if(!preg_match($illegal, $addr) && preg_match($format,$addr)) return true; return false; } ------------ Sunil Amber http://jformmail.sourceforge.net/

« previous php.notes (#90157) next »