2013-05-14 64 views
-1

我正在验证字段中只填写整数并验证该字段是否需要的字段?只能用整数填充的必填字段

我插入脚本代码如下:

<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" /> 
+2

他在2小时内发布了3个同类问题 – PSR 2013-05-14 12:31:30

+0

http://stackoverflow.com/questions/16538303/i-want-my-field-to-accept-only-integers-and-i-have-kept- that-field-in-required-v – PSR 2013-05-14 12:32:37

+0

@PSR是的。我正在结束他的其他问题。 – Antony 2013-05-14 12:32:43

回答

0

使用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/

+0

他在2小时内发布了3个同类问题 – PSR 2013-05-14 12:32:19

+0

如果我在我的代码中使用数字类型,那么我得到一个选择框,谢谢给我一些新的想法,但目前我不想要它,我只是想要如果有人输入一个变量,一个错误消息应该出现 – saika 2013-05-14 12:35:23