DarkPrince2005 Posted February 5, 2010 Share Posted February 5, 2010 Hi Everyone Ive written that validates a couple of fields after form submission, but would like to check that the values off an input box are only numbers. does anyone know how? Quote Link to comment https://forums.phpfreaks.com/topic/191029-number-validation/ Share on other sites More sharing options...
scotmcc Posted February 5, 2010 Share Posted February 5, 2010 Use a regular expression... preg_match('/\d{3}/', 123) Or, do it in JavaScript... It is usually a good idea to validate the input on the page rather than make the user wait to have you reload the page just to tell the user that he or she needed to use a specific input. See: http://us.php.net/manual/en/function.preg-match.php Quote Link to comment https://forums.phpfreaks.com/topic/191029-number-validation/#findComment-1007284 Share on other sites More sharing options...
DarkPrince2005 Posted February 5, 2010 Author Share Posted February 5, 2010 Unfortunately javascript isn't an option as it is a mobi site Quote Link to comment https://forums.phpfreaks.com/topic/191029-number-validation/#findComment-1007287 Share on other sites More sharing options...
oni-kun Posted February 5, 2010 Share Posted February 5, 2010 Unfortunately javascript isn't an option as it is a mobi site Use regular expressions, or ever is_numeric , is_float, is_double ..How hard can this be? Quote Link to comment https://forums.phpfreaks.com/topic/191029-number-validation/#findComment-1007289 Share on other sites More sharing options...
Hussam Posted February 5, 2010 Share Posted February 5, 2010 depends on what kind of numbers you are looking for, use one of these functions: is_numeric($value); is_float($value); is_double($value); I am not sure if there is more, but these are good enough. you can use is_int($value) to check if the type of the variable is integer. good luck. Quote Link to comment https://forums.phpfreaks.com/topic/191029-number-validation/#findComment-1007307 Share on other sites More sharing options...
thebadbad Posted February 5, 2010 Share Posted February 5, 2010 ctype_digit() will strictly check for numbers (in a string) only. Quote Link to comment https://forums.phpfreaks.com/topic/191029-number-validation/#findComment-1007309 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.