[英]I want only numeric in my text box (I want only work with input id or class)
This is my input field, I want right aj query code for only numeric keyword type in this field. 这是我的输入字段,我想在此字段中仅输入数字关键字类型的aj查询代码。 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">
干得好
<input type="number" name="quantity" min="1" max="5">
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.