我想验证类似于输入表单的字符串,比如7hAM/17hpm,我尝试了许多模式,但没有重新编码。
发布于 2022-05-27 12:16:11
我假设字符串输入是基于12h格式的。
let regex = /^(([0]*[1-9]{1}|[1]+[0]|[1]*[1-2]{1})[h]\s(AM|PM))$/;
function testPattern(value) {
console.log(value + ' ==> ' + regex.test(value));
}
testPattern('7h AM');
testPattern('07h AM');
testPattern('17h AM');
testPattern('25h AM');
testPattern('12h AM');
testPattern('12h PM');
我希望这个解决方案对你有用。
https://stackoverflow.com/questions/72404478
复制相似问题