From: "Merritt, Dave" <[EMAIL PROTECTED]>

> I have a form on which the user is supposed to select a variable type
> (boolean, integer, real, date/time, text) from a select box and enter the
> default value for this selected variable type in a text box.  I'm trying
to
> validate that the default value entered matches the variable type selected
> i.e. user selects boolean so valid defaults could only be 0, 1, true,
false
> and anything else would generate an error, or the user selects integer and
> enters 1.7 for the default would also throw a flag.  I know that all of
the
> form values submitted from the web page are strings but is there a way to
> test/convert the strings against the other variable types.
>
> I'm sure that I'm not explaining this very well, but for example, if I use
> the following code I will always get an error displayed even if the user
> enters a valid value such as 3 in the default field because the form
values
> are always submitted as strings.

Well, if "(int)$string == $string", then the value is an integer. Same for
"(float)$string == $string" for a real number. Boolean would be easy, just
strtolower($string) as compare to 1, 0, 'true', or 'false'. Date/time
validation will probaby require a regular expression or breaking it up to
validate days/month, etc. That can get a little hairy. If they say "text",
well, anything goes, right? Maybe just make sure it's not empty()?

Let me know if you need more details. There are probably a ton of different
ways to do this.

---John Holmes...

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

Reply via email to