更新时间:2023-01-28 23:41:26
You should use the following method to validate if the input is indeed numeric, and then check the ranges
-isnumeric>使用JavaScript验证数字 - IsNumeric()
copied from Validate numbers in JavaScript - IsNumeric()
function IsNumeric(input)
{
return (input - 0) == input && input.length > 0;
}
使用这样(阅读输入后的 )
And use it like this (after reading the inputs)
if (!IsNumeric(day) || (day < 1) || (day > 31))
{/*handle wrong day here and return false*/}
if (!IsNumeric(month) || (month < 1) || (month > 12))
{/*handle wrong month here and return false*/}
if (!IsNumeric(year) || (year < 1900) || (year > 2100))
{/*handle wrong year here and return false*/}