Enter Only Numbers and Decimal Values Using jQuery
I have used this class only allowed positive numbers and one decimal only
$(document).ready(function() {
$('input.numbers').keypress(function (event) {
return isNumber(event, this)
});
});
// THE SCRIPT THAT CHECKS IF THE KEY PRESSED IS A NUMERIC OR DECIMAL VALUE.
function isNumber(evt, element) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (
// “-” CHECK MINUS, AND NO MINUS ALLOWED.
(charCode == 45 || $(element).val().indexOf('-') == -1) &&
// “-” CHECK MINUS, AND ONLY ONE.
/*(charCode != 45 || $(element).val().indexOf('-') != -1) && */
// “.” CHECK DOT, AND ONLY ONE.
(charCode != 46 || $(element).val().indexOf('.') != -1) &&
(charCode < 48 || charCode > 57))
return false;
return true;
}
Enter Only Numbers and Decimal Values Using jQuery
Reviewed by Ashok Sen
on
01:31:00
Rating:
No comments:
Post a Comment