我有textbox
用户只能插入numbers
。于是,我试着用下面的链接不允许小数进入文本框不起作用
但还是我能够插入[。](十进制)在文本框中。下面是我试过
$(".allownumericwithoutdecimal").on("keypress keyup blur",function (event) {
$(this).val($(this).val().replace(/[^\d].+/, ""));
if ((event.which < 48 || event.which > 57)) {
event.preventDefault();
}
文本框
<igtxt:WebNumericEdit ID="txtNoofPages" Width="24%" runat="server" CssClass="allownumericwithoutdecimal">
</igtxt:WebNumericEdit>
http://stackoverflow.com/questions/9204783/how-do-i-validate-a-decimal-field-with-jquery-and-regex – MusicLovingIndianGirl
与键输入瞎搞不是用户友好的,如果该值看起来无效并且让用户自己修复,那么只显示屏幕提示会更好。嗅探键不会阻止无效值被粘贴,或者拖放到字段中,哦,'$(this).val()'是执行this.value的非常低效的方法。 – RobG
@ MusicLovingIndianGirl:你给出的链接接受'.'小数。我不想要那个.. – BNN