Link to home
Start Free TrialLog in
Avatar of Bob Schneider
Bob SchneiderFlag for United States of America

asked on

HTML type="number" input doesn't allow decimals

Is there a way around this?  Otherwise, is there another way to validate an html input box to ensure that it is a number without using the old javascript validation function?

Thank you very much!
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bob Schneider

ASKER

Incredibly helpful...as always.
My Regular Expression foo is not very good, but I believe this will work.

var twoDigitDecimal = /^\d{5}\.\d{2}$/;
var num = '123.2.2';
if(!twoDigitDecimal.test(num)){
 
  alert ("not valid");
 
}  

Open in new window

What you can do using plan javascript or jquery is listen for a change in the field value, if there is a change, test it like above. Instead of an alert, you can put a note under the field.

Of course, make sure to validate this using vbscript on the server and assume that anything from the the browser is bad.