1

This is my input field, I want right a j query code for only numeric keyword type in this field. if user type string then can't do this .

<input type="tel" name="jobapp_phone" class="sjb-form-control sjb-phone-number sjb-required" id="jobapp_phone" required="required" autocomplete="off" placeholder="099876 54321">
Cœur
  • 37,241
  • 25
  • 195
  • 267
Sanjay Yadav
  • 243
  • 3
  • 20

2 Answers2

2

Here you go

  <input type="number" name="quantity" min="1" max="5">
fuzzybear
  • 2,325
  • 3
  • 23
  • 45
2

check this it allows only numbers in the text field

$(function() {
  $('#main').on('keydown', '#onlyNumbers', function(e){-1!==$.inArray(e.keyCode,[46,8,9,27,13,110,190])||/65|67|86|88/.test(e.keyCode)&&(!0===e.ctrlKey||!0===e.metaKey)||35<=e.keyCode&&40>=e.keyCode||(e.shiftKey||48>e.keyCode||57<e.keyCode)&&(96>e.keyCode||105<e.keyCode)&&e.preventDefault()});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="main">
 <input id="onlyNumbers" type="text" />
</div>
Ganesh Putta
  • 2,622
  • 2
  • 19
  • 26