Input Text that support only Floating Number JavaScript



HTML : 

<input type=”text” class=”number” />

JavaScript :

$(‘.number’).keypress(function (event) {
if (event.keyCode === 37 || event.keyCode === 39 || event.keyCode === 46 || event.keyCode === 8)
{
var sVal = $(this).val();
var nCountDot = sVal.split(“.”).length;
if (nCountDot < 2) {
return true;
} else {
event.preventDefault();
}
}
else if ((event.which != 46) && (event.which < 48 || event.which > 57))
{
event.preventDefault();
}
});

CSS :

.number{
text-align : right;
}

Leave a Reply