Re[2]: [PHP] Validating form field text input to be a specific variable type

From: Date: Wed, 07 Apr 2004 01:59:20 +0000
Subject: Re[2]: [PHP] Validating form field text input to be a specific variable type
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-182583@lists.php.net to get a copy of this message
Hello Dave, Wednesday, April 7, 2004, 2:41:15 AM, you wrote: MD> Okay seems to makes sense, but when I do the following it doesn't appear to MD> be working correctly, or I'm viewing my logic incorrectly one: MD> if ( (int)$PageOptions['Default'] == $PageOptions['Default'] ) { MD> // display a message if the integer of the default value matches the MD> default value } MD> Enter 5, message displayed, so correct MD> Enter 5.0, messaged displayed, incorrect MD> Enter 5.5, no message, so correct MD> Enter a, message displayed, incorrect MD> Enter 5.0a, message displayed, incorrect MD> Enter 5.5a, no message, so correct MD> Enter a5.5, message displayed, incorrect MD> What am I missing here? When casting to an Integer don't forget it will loose any floating point value, so 5.0 becomes 5 which according to above will display a message. 5.0a will cast to 5, 5.5a should also cast to 5, but might be rounding the wrong way? a5.5 will cast to 0. -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html

« previous php.general (#182583) next »