Connecting Tech Pros Worldwide Forums | Help | Site Map

Form Validation

Darren
Guest
 
Posts: n/a
#1: Nov 22 '05
Hello,

I am sure this subject has been done to death, but I would like to make
sure that a form post is an interger or a float.

I have used

if (!ctype_digit($current_value)

but this is true if the number contains a decimal point.

I probably need a good tutorial/guide on form validation.


Darren


Scott Johnson
Guest
 
Posts: n/a
#2: Nov 22 '05

re: Form Validation


Darren wrote:[color=blue]
> Hello,
>
> I am sure this subject has been done to death, but I would like to make
> sure that a form post is an interger or a float.
>
> I have used
>
> if (!ctype_digit($current_value)
>
> but this is true if the number contains a decimal point.
>
> I probably need a good tutorial/guide on form validation.
>
>
> Darren
>[/color]
How about using:
is_int() or
is_float()?
Chung Leong
Guest
 
Posts: n/a
#3: Nov 22 '05

re: Form Validation


Darren wrote:[color=blue]
> Hello,
>
> I am sure this subject has been done to death, but I would like to make
> sure that a form post is an interger or a float.
>
> I have used
>
> if (!ctype_digit($current_value)
>
> but this is true if the number contains a decimal point.
>
> I probably need a good tutorial/guide on form validation.
>
>
> Darren[/color]

There is is_numeric(), although the function is buggy in that it
doesn't recognize ".05" as a number.

Scott Johnson
Guest
 
Posts: n/a
#4: Nov 22 '05

re: Form Validation


Chung Leong wrote:[color=blue]
> Darren wrote:
>[color=green]
>>Hello,
>>
>>I am sure this subject has been done to death, but I would like to make
>>sure that a form post is an interger or a float.
>>
>>I have used
>>
>> if (!ctype_digit($current_value)
>>
>>but this is true if the number contains a decimal point.
>>
>>I probably need a good tutorial/guide on form validation.
>>
>>
>>Darren[/color]
>
>
> There is is_numeric(), although the function is buggy in that it
> doesn't recognize ".05" as a number.
>[/color]
is_numeric will recognize decimals such as .05 as numeric. It may be
that your code is type casting that value to a char.

If you can maybe send some code, unless someone in here has an opinion
on this.
Chung Leong
Guest
 
Posts: n/a
#5: Nov 22 '05

re: Form Validation


I remembered incorrectly. The function recognizes positive numbers with
leading decimal but not negative ones. In any event, it's buggy.

Closed Thread