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....

-dan
----- Original Message ----- 
From: "Ralph" <[EMAIL PROTECTED]>
To: "'Daniel J. Rychlik'" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Friday, May 30, 2003 12:59 PM
Subject: RE: [PHP] preg_match array question


>
> Try this:
>
> Let say you have these three fields in your form:
>
> <INPUT TYPE="text" VALUE="num[1]">
> <INPUT TYPE="text" VALUE="num[2]">
> <INPUT TYPE="text" VALUE="num[3]">
>
> then use the following to iterate through each field:
>
> foreach($_POST['num'] as $key => $value){
>     preg_match ( '(foo)' , $_POST["num"][$key] );
> }
>
> or you can also try this:
>
> $c = count($num);
> for($i; $i < $c; $i++){
>     preg_match ( '(foo)' , $_POST["num"][$i] );
> }
>
> this should get you started.
>
> -----Original Message-----
> From: Daniel J. Rychlik [mailto:[EMAIL PROTECTED]
> Sent: Friday, May 30, 2003 9:48 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] preg_match array question
>
> Hey,
>
> Im trying to use preg_match to validate numbers in multiple fields.  I
> can check one field but Im having trouble checking multiple fields.
>
> preg_match ( '(foo)' , $_POST["num1"] ); <- That works fine.  but I need
> to check multiple fields.
>
> I thought I would build an array with the POST data like this...
>
> $num = array ($_POST["num1"],
>                     ($_POST["num2"]);  There are more than that...
>
> and then use
> preg_match ('(foo)', $num) ;   $num should point to my array, but that
> doesnt work.  I get a warning message.. and it doesnt check the first
> num1 in the array.
>
> Im certain that Its my code, and I wanted to get some input on what Im
> doing wrong.
>
> -Dan
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to