gpt4 book ai didi

javascript - MM/DD 验证。它没有 YYYY 也应该验证 02/30 我也不能

转载 作者:行者123 更新时间:2023-11-28 02:59:45 24 4
gpt4 key购买 nike

function isMMDD(value) {
var re = /^([0]?[1-9]|1[0-2])\/([0-2]?[0-9]|3[0-1])$/;
if (re.test(value)) {
return true;
}
else
return false;
}

I would like to have 02/30 as invalid too.

最佳答案

信息在here

If you are validating the user's input of a date in a script, it is probably easier to do certain checks outside of the regex. For example, excluding February 29th when the year is not a leap year is far easier to do in a scripting language. It is far easier to check if a year is divisible by 4 (and not divisible by 100 unless divisible by 400) using simple arithmetic than using regular expressions.

在你的情况下它适用同样的事情,这也是一个非常常见的问题。

here , here还有(但不完全是)here

关于javascript - MM/DD 验证。它没有 YYYY 也应该验证 02/30 我也不能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46270397/

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