必填字段,只能用整数填充 [英] Required field that should be filled only with integers
本文介绍了必填字段,只能用整数填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究一个字段的验证,在该字段中只能用整数填充,并给出是否需要该字段的验证?
I am working upon validation of a field where in the field should be filled only with integers and validation that the field is needed is also given?
我插入了脚本标签,如下所示:
I inserted the script tags as follows:
<script type="text/javascript" src="jquery.numeric.js"></script>
<script>
jQuery(document).ready(function(){
$("#estvalue").numeric({
negative: false
},
function() {
alert("No negative values");
this.value = "";
this.focus(); });
});
</script>
<input name="Est_Value" id="estvalue" class="regi_input_1" style="width: 150px; height: 25px;" type="text" />
推荐答案
使用HTML5
<input type="number" min="0" />
<input name="Est_Value" id="estvalue" class="regi_input_1" style="width: 150px; height: 25px;" type="number" min="0" />
使用JavaScript进行验证
<input name="Est_Value" id="estvalue" class="regi_input_1" style="width: 150px; height: 25px;" type="text" onkeypress="if ( isNaN( String.fromCharCode(event.keyCode) )){ alert('numbers only'); return false; }" />
工作演示 http://jsfiddle.net/cse_tushar/FEVrB/
这篇关于必填字段,只能用整数填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文