我有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