Vijay Kumar Vijay Kumar - 7 days ago 5
Javascript Question

Disable only .(DOT) special charecter in input field

I don't want allow user to enter. (Dot) in my input field.. Rest of the required validation done already.



function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
return false;

return true;
}

<input type="text" class="form-control" name="ContactNumber" maxlength="10" value="" id="ContactNumber" title="Enter Number Here" onkeypress="return isNumberKey(event)" required>




Answer

$("#name").on("keypress",function(evt){
    var keycode = evt.charCode || evt.keyCode;
      if (keycode  == 46) {
        return false;
      }
});
<input type="text" id="name" />

Working example here: jsfiddle