我写了这个函数:
function validateName(name) {
var re = /^[a-zA-Z\s]+$/gim;
console.log("@@ name = ", name);
console.log("typeof(re) = ", typeof(re));
console.log("test returns = %s,re = ", re.test(name),re);
console.log("test returns = %s,re = ", re.test(name),re);
console.log("test returns = %s,re = ", re.test(name),re);
return (re.test(name));
}
当我用名字="用户十五"我明白了:
@@ name = user fifteen
typeof(re) = object
test returns = true,re = /^[a-zA-Z\s]+$/gim
test returns = false,re = /^[a-zA-Z\s]+$/gim
test returns = true,re = /^[a-zA-Z\s]+$/gim
正如你所看到的,有时候我会变得真实而有些虚伪。我注意到这是因为全局匹配标志,但我无法理解为什么。 有没有人有想法?
提前谢谢