Re: preg_match array question

From: Date: Fri, 30 May 2003 20:03:40 +0000
Subject: Re: preg_match array question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-149596@lists.php.net to get a copy of this message
perhaps I am misunderstanding... I have snipit of my foreach. I have a preg_match that checks for a valid email address. basically it just checks for an @ and a . When I place this in my loop all of the keys are evaluated, so hence the name key is evaluated and thrown error because of the check. To remedy this problem I took it out of the loop and it worked fine. Ultimately I would love to keep it in the loop and throw checks for certain fields, but syntaxtually it doesnt work for me. Any Suggestions ? foreach ($_POST as $key=>$value) { # Begin Foreach loop if (empty($value)) { # Begin If echo "$key :: Missing Data<br/>"; if (!preg_match('/([a-z0-9\-\.\#\:]+@[a-z0-9\-]+\.[a-z0-9\-]+)/i', $_POST["eaddy"])) {echo $_POST["eaddy"]," is not a valid address.<br/>"; } } # End if else { echo "$key, ->Ok<br/>";} } # End Foreach ----- Original Message ----- From: "Ralph" <ralph@nqionline.com> To: "'Daniel J. Rychlik'" <drychlik@tcsconsult.com>; <php-general@lists.php.net> Sent: Friday, May 30, 2003 2:42 PM Subject: RE: [PHP] preg_match array question > Not sure if I'm misunderstanding, but I know that foreach() will do > this. > > -----Original Message----- > From: Daniel J. Rychlik [mailto:drychlik@tcsconsult.com] > Sent: Friday, May 30, 2003 11:58 AM > To: Ralph; php-general@lists.php.net > Subject: Re: [PHP] preg_match array question > > The problem is, that I have multiple fields and what I am trying to do > is > check each field to make sure I get the data that I need and not some > crap, > like letters in a number field or a <script> tag in a field. Things of > this > sort. The foreach loop wont work for me in this instance because Im > checking for proper input. > > I can write multiple elseif statements to check each field but alas, > this is > not optimal. I may go ahead and write this to get it done and then go > back > and put it to the write board.... > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#149596) next »