Okay seems to makes sense, but when I do the following it doesn't appear to be working correctly, or I'm viewing my logic incorrectly one:
if ( (int)$PageOptions['Default'] == $PageOptions['Default'] ) { // display a message if the integer of the default value matches the default value } Enter 5, message displayed, so correct Enter 5.0, messaged displayed, incorrect Enter 5.5, no message, so correct Enter a, message displayed, incorrect Enter 5.0a, message displayed, incorrect Enter 5.5a, no message, so correct Enter a5.5, message displayed, incorrect What am I missing here? Thanks, Dave Merritt [EMAIL PROTECTED] -----Original Message----- From: John W. Holmes [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 06, 2004 3:19 PM To: Merritt, Dave; [EMAIL PROTECTED] Subject: Re: [PHP] Validating form field text input to be a specific variable type 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