Sanjay Yadav Sanjay Yadav -4 years ago 102
jQuery Question

I want only numeric in my text box(my questionis diffrent becouse I wantonly work with input id or class)

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">

Answer Source

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=""></script>
<div id="main">
	<input id="onlyNumbers" type="text" />

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download