ainoy31 Posted June 4, 2007 Share Posted June 4, 2007 What is the best way to validate that the decimal field is filled with the properly data in a form? I have a field that ask the user to enter a price quote. I do not want letters or symbols allowed. Much appreciation. thx. AM Quote Link to comment https://forums.phpfreaks.com/topic/54172-decimal-field-validation/ Share on other sites More sharing options...
Wildbug Posted June 4, 2007 Share Posted June 4, 2007 is_float() Or you could use a regular expression -- /\d*(?:\.\d+)?/ Quote Link to comment https://forums.phpfreaks.com/topic/54172-decimal-field-validation/#findComment-267824 Share on other sites More sharing options...
Wildbug Posted June 4, 2007 Share Posted June 4, 2007 Oops, correction. Since form input is always a string, is_float() can't be used since it is intented for checking variables types. PHP recommends using is_numeric(), but that'll also allow exponential formats. Check out floatval(). Quote Link to comment https://forums.phpfreaks.com/topic/54172-decimal-field-validation/#findComment-267825 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.