Javascript charCodeAt()处理一些验证,但不处理其他验证
我本可以发誓,在我的老师决定寻找每一个可能的字符组合并以某种方式记录我10分之前,我都正确地验证了一切。因此,我在我的代码中尝试修复验证,但是,尽管这就像他演讲提纲中的示例一样,它决定让a1毫不犹豫地通过表单。我用下面的代码仔细检查了ascii字符代码表 而1号仍然在通过。这是我的代码部分:Javascript charCodeAt()处理一些验证,但不处理其他验证,javascript,validation,character,Javascript,Validation,Character,我本可以发誓,在我的老师决定寻找每一个可能的字符组合并以某种方式记录我10分之前,我都正确地验证了一切。因此,我在我的代码中尝试修复验证,但是,尽管这就像他演讲提纲中的示例一样,它决定让a1毫不犹豫地通过表单。我用下面的代码仔细检查了ascii字符代码表 而1号仍然在通过。这是我的代码部分: else if(f1.state.value.length != 2 || !( (f1.state.value.charCodeAt(0)>=65 && f1.state.
else if(f1.state.value.length != 2 ||
!( (f1.state.value.charCodeAt(0)>=65 && f1.state.value.charCodeAt(0)<=90) ||
(f1.state.value.charCodeAt(1)>=97 && f1.state.value.charCodeAt(1)<=122) ))
{
alert('Please enter a state in abreviated form');
f1.state.focus();
return false;
}
else if(f1.state.value.length!=2 ||
!((f1.state.value.charCodeAt(0)>=65&&f1.state.value.charCodeAt(0)=97&&f1.state.value.charCodeAt(1)有趣的是,我取出了!并将它放在每个圆括号中,它起了作用。。因此,如果其中一个为真,它将返回真……然后!对它进行运算
所以应该是:
else if(f1.state.value.length != 2 ||
( !(f1.state.value.charCodeAt(0)>=65 && f1.state.value.charCodeAt(0)<=90) ||
!(f1.state.value.charCodeAt(1)>=97 && f1.state.value.charCodeAt(1)<=122) ))
{
alert('Please enter a state in abreviated form');
f1.state.focus();
return false;
}
else if(f1.state.value.length!=2 ||
(!(f1.state.value.charCodeAt(0)>=65&&f1.state.value.charCodeAt(0)=97&&f1.state.value.charCodeAt(1)