<!DOCTYPE html>
<html>
<head>
<script src="js/jquery-3.6.0.js"></script>
</head>
<body>
<table>
<tr>
<td><strong>Decimal :</strong></td>
<td>
<input type="text" name="numeric" class="allow_decimal" />
<div>Allow numeric values with decimal</div>
</td>
</tr>
</table>
<script>
$(document).ready(function () {
$(".allow_decimal").on("input", function (evt) {
var self = $(this);
self.val(self.val().replace(/[^0-9\.]/g, ""));
if (
(evt.which != 46 || self.val().indexOf(".") != -1) &&
(evt.which < 48 || evt.which > 57)
) {
evt.preventDefault();
}
});
});
</script>
</body>
</html>
Github Link: https://github.com/adi501/JQuery-Examples
No comments:
Post a Comment