How to do decimal validation using javascript?
There is a text box which should accept only 24.00 or 24 or any value less than 24.00. The text box also must allow if 23.99 is entered.
I tried it this way:
if (document.forms[0].hours!= undefined) {
var val = document.forms[0].hours.value;
if (val .match(/^\d{0,6}(?:\.\d{0,2})?$/)) {
alert("Invalid" +'${payType}'+" Hours. The hours entered can not have more than 2 decimal places or should be in the range of 0 to 24 ");
submitted=false;
return false;
}
}
The values can be: 1.00 or 12.25 or 1.25 or 23.99 or 24 but not above these values. Any number below 24.00 or 24.
(val < 24)
;