How to allow only positive numeric value to a text box using jquery

Below is the nice piece of code which allows only positive numeric value to a text box.

HTML:

<input type=”text” id=”txtPostiveInt” />

Jquery:

$(document).ready(function () {
$(‘#txtPostiveInt’).keyup(function () {
var numbers = $(this).val();
$(this).val(numbers.replace(/D+/, ”));
});
});


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.