dedi wibisono
dedi wibisono

Reputation: 533

Filter Input type number using javascript

How do I not allowed when typing "2" when first typing? Is possible using JavaScript?

<input type="number"/>

Only "2" can not typing when start. Any body help? Thank you.

Upvotes: 0

Views: 100

Answers (1)

Amadan
Amadan

Reputation: 198314

$('input').keypress(function(evt) {
  if (evt.which == "2".charCodeAt(0) && $(this).val().trim() == "") {
    return false;
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number"/>

Upvotes: 1

Related Questions