/////////////////////////////// HTML
<input type="text" name="decimal" id="decimal" onkeypress="return Validate_NumerDecimal(this,event,8)">
//////////////////////////// JQUERY
<script>
/////////////////////////// onkeypress
function
Validate_NumerDecimalPress(th, event, mxlen, decNum) {
if ((event.which != 46) &&
((event.which < 48 || event.which > 57) &&
(event.which != 0 && event.which != 8))) {
event.preventDefault();
return false;
}
debugger;
var dotPos = $(th).val().indexOf('.');
if (dotPos < 0) {
if
($(th).val().length < mxlen || event.keyCode == 46) {
return true;
}
else {
event.preventDefault();
return false;
}
}
else {
if
($(th).val().length >= dotPos && $(th).val().length < dotPos + 3
&& event.keyCode != 46) {
debugger;
var number =
th.value.split('.');
var caratPos =
getSelectionStart(th);
if (caratPos
<= dotPos) {
if (number[0].length < mxlen) {
return true;
}
else { event.preventDefault(); return false; }
}
else if (caratPos > dotPos && dotPos > -1
&& (number[1].length > decNum)) {
event.preventDefault(); return false;
}
else {
return true;
}
}
else {
event.preventDefault();
return false;
}
}
}
</script>
No comments:
Post a Comment