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!
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
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


Incredibly 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';
  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.