写一个javaScript的正则要求输入的文本需要包含数字
可以使用正则表达式 \d 来匹配数字,可以通过 test() 方法来判断输入的文本是否包含数字,例如:
var text = "Hello world 123";
var regex = /\d/;
if (regex.test(text)) {
console.log("包含数字");
} else {
console.log("不包含数字");
}
输出结果为:包含数字。
原文地址: https://www.cveoy.top/t/topic/g9WA 著作权归作者所有。请勿转载和采集!