0
接受自然數這是我的jQuery代碼jQuery驗證從asp.net文本框
$(document).ready(function() {
$('#txtLoadCode').keydown(function (key) {
if ($(this).val().substring(0, 1) == '0') {
$(this).val('');
return false;
} else {
var keycode = (key.which) ? key.which : key.keyCode;
var code = document.getElementById('<%=txtLoadCode.ClientID%>').value;
if ((!(keycode == 8 || keycode == 46)) && (keycode < 48 || keycode > 57)) {
return false;
} else {
//Condition to check textbox contains ten numbers or not
if (code.length < 5 || keycode == 8) {
return true;
} else {
return false;
}
}
}
});
});
這有助於我接受一個5位數字。但是當我只輸入0時,它仍然接受。我想避免這種情況。
請幫
嘗試..... – iJade
由於其工作:) – user2124167
高興它helped..posted作爲一個答案... upvote並標記爲答案:) – iJade