以下是我的查看页面,
<table class="width_full cellspace" border="0" cellspacing="0" cellpadding="0" style="vertical-align:top">
<tr>
<td colspan="3">
<strong>@Html.Label(Model.objTRSkillGradeLabelEntities.lblBPBlockedfor)</strong>
</td>
</tr>
<tr style="font:11px/20px Arial, Helvetica, sans-serif">
<td style="width: 33%;">
AccountId
<span class="redFont">*</span> :
<input type="text" id="txtBlkAccountId" />
<label id="lblAccountId" class="error"> </label>
</td>
</tr>
<tr>
<td colspan="3" class="textCenter">
<input class="btnInput" type="submit" value=@Model.objTRSkillGradeLabelEntities.btnBPSubmit onclick="javascript:UpdateTRData();" />
</td>
</tr>
</table>
function UpdateTRData() {
var errorflag;
document.getElementById('lblAccountId').innerText = "";
var BlkAccountIdV = $('#txtBlkAccountId').val();
if (BlkAccountIdV == "" || BlkAccountIdV == null) {
document.getElementById('lblAccountId').innerText = "Enter AccountID";
errorflag=1;
}
var txtLength = $("#txtBlkAccountId").val().length;
if (txtLength != 7) {
document.getElementById('lblAccountId').innerText = "Enter valid AccountID";
errorflag = 1;
}
var i;
s = txtLength.toString();
for (i = 0; i < s.length; i++) {
var c = s.charAt(i);
if (isNaN(c)) {
document.getElementById('lblAccountId').innerText = "Enter valid AccountID";
errorflag = 1;
}
}
if (errorflag == 1) {
return false;
}
var AssociateID = $('#lblAssoID').text();
var BlkAccountId = $('#txtBlkAccountId').val();
$.ajax({
url:"@Url.Action("UpdateBlockDetails", "TravelReady")",
data:{
strAssociateID: AssociateID,
strBlkAccountId: BlkAccountId
},
dataType: "json",
type: "POST",
error: function(e) {
alert(e.getException().getMessage());
alert("An error occurred.");
},
success: function(data) { return data; }
});
}
我已验证帐户 ID 文本框只接受 7 位数字。单击按钮后,此验证将起作用。我需要再做一个验证,比如不能输入超过 20 个数字。也就是说,如果我输入第 21 位,应该会显示警报框。如何使用 jQuery 执行此验证?