<html>
<head>
<title>..</title>
<script language="vbscript">
sub checkdata()
if form.username=empty then
window.alert "用户名不能为空。。"
exit sub
end if
for i=1 to len(form.username)
c=lcase(mid(form.username,i,1))
if instr("abcdefghijklmnopqrstuvwxyz0123456789_",c)=0 then
window.alert "用户名不符合规范。。"
exit for
exit sub
end if
next
form.submit
end sub
</script>
<body..>
<form method="post" action="add.asp" name="form">
<table..>
<tr..>
<td..>
用户名:
<input type="text" name="username" size=20>
</td>
</tr>
<tr..><td..>
<input type="button" name="submit" value="确定" onclick=checkdata">
</td></tr>
</table>
</body>
</html>
以上代码在验证用户名为空的时候还是有用,可以弹出”用户名不能为空。。"的警告框,但是下面的几行代码,验证输入的是否是字母和数字以及“_"的时候就出问题了我无论输入什么,它都会弹出”用户名不符合规范。。"的字样。
我就不知道我错在哪里。请大家帮帮忙。
需不需要form.username.value啊
if instr("abcdefghijklmnopqrstuvwxyz0123456789_",c)
这句的意思是,如果c是"abcdefghijklmnopqrstuvwxyz0123456789_"的子串,则。
哈哈,c不会那么巧就是它的子串吧。
楼主的意思是用户的注册名只能是中文吗?