validation- before and after decimal take only two digits
validation in jquery- before and after decimal take only two digits on keypress
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dharmraj ThakurPosted May 2, 2017, 1:44 AM
Nimish SaxenaPosted May 2, 2017, 1:54 AM
Nimish SaxenaPosted May 2, 2017, 1:26 AM
Nimish SaxenaPosted May 2, 2017, 1:15 AM
Waruna ManjulaPosted May 2, 2017, 1:08 AM
Nimish SaxenaPosted May 2, 2017, 1:04 AM
Waruna ManjulaPosted May 2, 2017, 12:46 AM
padding: 5px 10px;
font-size: 16px;
}
var $this = $(this);
if ((event.which != 46 || $this.val().indexOf('.') != -1) &&
((event.which < 48 || event.which > 57) &&
(event.which != 0 && event.which != 8))) {
event.preventDefault();
}
var text = $(this).val();
if ((event.which == 46) && (text.indexOf('.') == -1)) {
setTimeout(function() {
if ($this.val().substring($this.val().indexOf('.')).length > 3) {
$this.val($this.val().substring(0, $this.val().indexOf('.') + 3));
}
}, 1);
}
if ((text.indexOf('.') != -1) &&
(text.substring(text.indexOf('.')).length > 2) &&
(event.which != 0 && event.which != 8) &&
($(this)[0].selectionStart >= text.length - 2)) {
event.preventDefault();
}
});