var pat5 =/^[0-9a-zA-Z._-]+[@][0-9a-zA-Z_-]+[.]([a-zA-Z]){1}$/;
inputs[4].onblur=function(){
if(pat5.test(this.value)){
spans[4].innerHTML = "正确";
console.log(111);
}else{
spans[4].innerHTML="格式不正确";
console.log(222);
}
}
在我们验证表单的时候一定慎重加g,因为这个g表示全局搜索,如果加g表示在全局搜索,第一次搜索到,第二次就不是从0开始搜索了,这样会出现bug,因此解决这种方法:不加g或者设置pat5.listIndex = 0;这样就可以了。