note 46033 added to function.preg-match

From: Date: Mon, 27 Sep 2004 18:08:50 +0000
Subject: note 46033 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-77443@lists.php.net to get a copy of this message
Here's something to help out all the nubs -- a nice email validation regex. It doesn't handle IP addressed domains, but who cares. It allows . and - characters but not as leading or trailing chars. It also won't allow repeats of said chars. will match: u.r.teh.sux0r@hotmail.com won't match -blah-@blah.u.go.girl.com or bla--h@red.herrning.net peace out -- retry NOTE: remove the spaces in the regex function checkEmail($email) { if ( !preg_match( "#^[\w|\d] +(([\-|\.][\w|\d]+)+) ?@([\w|\d|\-]+\.)+[\w]{2,3}$#" , $email) ) return 1; return 0; } then use it like this in your scripts: if ( checkEmail($instanceEmail) ) $errormsg = "Your email address blows."; ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46033 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46033&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+46033&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77443) next »