Re: Form Validation filter - Regex Q

From: Date: Thu, 12 Nov 2009 09:06:32 +0000
Subject: Re: Form Validation filter - Regex Q
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-299781@lists.php.net to get a copy of this message
On Tue, 10 Nov 2009 09:34:52 -0800, Haig Davis wrote: > foreach($_POST as $keyTemp => $valueTemp){ > $key = mysqlclean($keyTemp); > $value = mysqlclean($valueTemp); Mysql and form validation are totally unrelated. In my mind, this seems spectacularly misguided. > if($key = ("$customerServiceEmail") || ("$billingEmail")){ > > if(preg_match("/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$/", > $value)){ Just as almost every other email validation regexp I have seen, this has a few imperfections: * It does not allow some valid email addresses (mail!box@example.com) * It does not allow some valid domains (*.museum) * It allows invalid email addresses (.@example.com) * It allows invalid domains (example..com) > $style = "yellow"; > $formMsg = "Invalid Characters"; > $bad = $key; Personally, I'd put the invalid keys in an array and mark all the problematic fields at once. /Nisse

« previous php.general (#299781) next »