Rajar Ahmed
asked on
check currency format on keypress event
how to create textbox with following rules
1. Need to accept atleast 1 or maximum 8 digits before decimal Like 12345678.00 is allowed and
123456789.00 9 should not be allowed to enter in onkeypress event as length exceeds 8 length
2. after decimal only two digits should be allowed
1. Need to accept atleast 1 or maximum 8 digits before decimal Like 12345678.00 is allowed and
123456789.00 9 should not be allowed to enter in onkeypress event as length exceeds 8 length
2. after decimal only two digits should be allowed
You can try this regex value:
^[0-9]{1,8}([\.][0-9]{1,2} )?$
^[0-9]{1,8}([\.][0-9]{1,2}
ASKER
hi disrupt ,
it was close
but it fails two condition
1.if 123456789-> 9 should be cleared and only 12345678 should exists
2.Decimal is not mandatory it should not accept more than 2 now error message display when i put dot ie 1234568. this condition it fails and error msg displayed.
it was close
but it fails two condition
1.if 123456789-> 9 should be cleared and only 12345678 should exists
2.Decimal is not mandatory it should not accept more than 2 now error message display when i put dot ie 1234568. this condition it fails and error msg displayed.
function ka(keyValue) {
var re = new RegExp("^[0-9]{1,8}([\.][0-9]{1,2})?$");
if (!keyValue.match(re)) {
document.getElementById("errmsg").innerHTML = 'invalid';
}
else {
document.getElementById("errmsg").innerHTML = '';
}
}
<input type="text" id="idTest" onkeyup="return ka(this.value)" maxlength="15"/><div id="errmsg" ></div>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
^\d{8}(\.\d{1,2})?$