The below code is to validate any input of decimal type with a precision of 2.
function check() {
var str = $('#txttest').val();
var patt = new RegExp("^[0-9]+(\.[0-9]{1,2})?$");
var res = patt.test(str);
alert(res);
}
Valid examples:
12
12.00
12.00a
12a
a12
1a2.00
Failed Case:
In some cases, the function is returning wrong values, like 1a2.
Now, please suggest.