|
Posted by Jerim79 on 12/07/06 17:07
Jerim79 wrote:
> I am working on form validation. I have a scheme that is working for
> me, except for 3 input fields. Zip, Phone, and Fax are the input
> fields. I want to do two tests. First I want to check to make sure
> there is data actually in the box. Next, I want to make sure that data
> is only numbers.
>
> The scheme I am using is:
>
> $Zip=stripslashes($_POST["Zip"]);
>
> function check_zip($Zip)
> {
> if(!preg_match("/[^0-9]+$/ ",$Zip))
> return TRUE;
> else
> return FALSE;
> }
>
> if(!check_zip($Zip))
> {
> $msg7="Please input a valid 5 digit zip code. (No letters or special
> characters.)";
> $error++;
> }
>
> if ($Zip="")
> {
> $msg7="Please input a valid 5 digit zip code. (No letters or special
> characters.)";
> $error++;
> }
>
> Granted, I just read up on pregmatch today so it is new to me. The
> problem I am having is that it doesn't report that the box is empty. If
> I type letters into the box, it returns the error message, asking for a
> valid 5 digit zip code. So the first IF seems to be working. If I put
> the second IF in front of the first (rearrange them) it still doesn't
> work. I thought "" was the basic way to check for NULL data across most
> languages. I tried looking it up on the PHP website but didn't find
> anything to indicate a different syntax. I tried doing an IF/ELSE but
> that didn't work either. Any help is appreciated.
Forgot to mention that I know you don't have to have two IF statements.
The first IF should return an error when it doesn't find numbers. But
that wasnt' working either.
Navigation:
[Reply to this message]
|