num = numreplace^dig 正则验证只能输入数字并且小于100大于0
To validate that the input "num" only contains digits and is greater than 0 but less than 100, you can use the following regular expression:
num = num.replace(/\D/g,''); // Remove all non-digit characters
if (num > 0 && num < 100) {
// num is valid
} else {
// num is invalid
}
Here, the regular expression /^\d+$/ is used to match only digits. The ^ and $ anchors ensure that the entire input is matched and no other characters are present. The + quantifier allows for one or more digits.
After removing all non-digit characters from the input using the replace method, you can check if the resulting number is greater than 0 and less than 100 to determine if it is valid.
原文地址: http://www.cveoy.top/t/topic/jceH 著作权归作者所有。请勿转载和采集!