请大家看看ASP函数错在哪里?

来源:百度知道 编辑:UC知道 时间:2024/05/26 17:31:19
if (len(sfzh)<>15 or len(sfzh)<>18) then
response.write "<script language='javascript'>alert('身份证号格式错误,请重新输入!');window.location.href='javascript:history.go(-1)';</script>"
response.end
end if

就算输入的号码正确它也弹出提示,帮忙改改,谢谢

if (len(sfzh)<>15 or len(sfzh)<>18) then
应改为
if (len(sfzh)<>15 and len(sfzh)<>18) then

因为上面的代码存在逻辑错误
不管 len( sfzh ) 的值是多少
(len(sfzh)<>15 or len(sfzh)<>18) 这句永远为真

PS:应注意代码运行效率

比如 if (len(sfzh)<>15 and len(sfzh)<>18) then
,此处调用了两次 len 函数来计算字符串长度,
最好改为

Dim inputLen
inputLen = Len( sfzh )
if ( inputLen <> 15 AND inputLen <> 18 ) Then
'...
End If