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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dharmraj ThakurRank #577 · 4.2K reputationPosted May 1, 2017, 9:44 PM EDT
Nimish SaxenaRank #2,279 · 618 reputationPosted May 1, 2017, 9:04 PM EDT
Waruna Manjula51 reputationPosted May 1, 2017, 8:46 PM EDT
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();
}
});
Waruna Manjula51 reputationPosted May 1, 2017, 9:08 PM EDT
Nimish SaxenaRank #2,279 · 618 reputationPosted May 1, 2017, 9:15 PM EDT
Nimish SaxenaRank #2,279 · 618 reputationPosted May 1, 2017, 9:26 PM EDT
Nimish SaxenaRank #2,279 · 618 reputationPosted May 1, 2017, 9:54 PM EDT