gpt4 book ai didi

javascript - 如何验证特定格式的大厅票号

转载 作者:行者123 更新时间:2023-11-30 18:11:33 25 4
gpt4 key购买 nike

我正在做一个根据给定的 HallTicket 编号显示学期明智分数的项目。

因此,我必须使用 JavaScript 验证输入的大厅票号。

大厅票号有以下限制:

--->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.

谁能说说如何编写 JavaScript 来验证这种大厅票号?

最佳答案

一个(稍微测试过的)非正则表达式解决方案

function validateTicketNum(numb){
var first = ["10","11","12"];
var third = ["02","04","05","12"];
if (numb.length!==10){
return false;
}
else if (first.indexOf(numb.substring(0,2))==-1){
return false;
}
else if (numb.substring(2,6)!=='kp1a'){
return false;
}
else if (third.indexOf(numb.substring(6,8))==-1){
return false;
}
else if (isNaN(numb.substring(8,10)) ||
parseInt(numb.substring(8,10),10) < 1 ||
parseInt(numb.substring(8,10),10) > 60){
return false;
}
return true;
}

关于javascript - 如何验证特定格式的大厅票号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14457468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com