问题描述
我正在做一个根据给定的HallTicket编号显示学期明智标记的项目。因此,我必须使用javascript为输入的Hall票号提供验证。并且门厅门票号码有以下限制
--->它显然只有10个字符
--->开始两个位置可能是10或11或12
--->接下来的四个位置必须是字符串kp1a
--->后两个位置可能包含任何一个02或04或05或12只有
--->重新发送两个位置可能是01到60之间的任何数字。
任何人都可以说如何编写javascript进行验证这种门票号码。
请帮帮我。提前谢谢。
I am doing a project that displays the semester wise marks according to the given HallTicket Number. So, i have to provide validation for entered Hall ticket number using javascript. And hall ticket number has following constraints
--->It shouid hav exactly 10 characters
--->starting two positions may be 10 or 11 or 12
--->next four positions must be the string "kp1a"
--->later two positions may contains any of 02 or 04 or 05 or 12 only
--->remaing two positions may any digits from 01 to 60.
Can any one say How to write javascript for validating this kind of Hall ticket number.
Please help me. thanks in advance.
推荐答案
<script language="javascript" type="text/javascript">
function fnValidate() {
var ticket = document.getElementById("txtTest").value.toLowerCase();
var status = "";
var C1 = ticket.substr(0, 2);
var C2 = ticket.substr(2, 2);
var C5 = ticket.substr(4, 1)
var C6 = ticket.substr(5, 1);
var C3 = ticket.substr(6, 2);
var C4 = ticket.substr(8, 2);
if (ticket.length == 10) {
if (C1 == "10" || C1 == "11" || C1 == "12") {
if (C2 == "kp" && parseInt(C5)==1 && C6=="a") {
if (parseInt(C3) == 02 || parseInt(C3) == 04 || parseInt(C3) == 05 || parseInt(C3) == 12) {
if (C4 > 0 && C4 <= 60) {
status = "valid";
}
}
}
}
}
if (status != "") {
alert("Valid");
}
else {
alert("InValid");
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtTest" runat="server" Height="30px" Width="80px" MaxLength="10"></asp:TextBox><br />
<asp:Button ID="btnValidate" runat="server" Text="Vaildate" OnClientClick="fnValidate()"/>
</div>
</form>
</body>
这篇关于如何验证特定格式的Hall Ticket编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!