用vbs写表单验证

来源:百度知道 编辑:UC知道 时间:2024/06/05 18:06:14
<SCRIPT language=vbscript>

</SCRIPT>

<META content="MSHTML 6.00.2900.3132" name=GENERATOR></HEAD>
<BODY topMargin=6>
<TABLE border=0 aligen="center">
<TBODY>
<TR>
<TD vAlign=top> </TD>
<TD vAlign=top align=middle><!—表单输入区定义-->
<FORM name=reg_form method=get>
<TABLE style="FONT-SIZE: 12px; align: left" borderColor=gold cellPadding=4
width=550 bgColor=lavenderblush border=1>
<TBODY>
<TR>
<TD width=850 ailgn="left"> 用户名  <INPUT size=16
name=usrname>  密码  <INPUT type=password size=12 name=pass>
 再输一遍密码  <INPUT type=password size=12 name=pass2> </TD></TR>
<TR>
<TD align=left widt

搞定了,代码如下:

<html>
<head>
<SCRIPT language=vbscript>
function checkForm()
if trim(reg_form.usrname.value )="" then
msgbox("用户名不能为空!")
reg_form.usrname.focus()
exit function
end if

Set regEx = New RegExp
regEx.Pattern="^[a-zA-Z\_\u4e00-\u9fa5]+$"
if not regEx.Test(reg_form.usrname.value) then
msgbox("用户名必须是中文,字母大小写,下划线")
reg_form.usrname.focus()
reg_form.usrname.select()
exit function
end if

if (reg_form.pass.value="") or len(reg_form.pass.value)>12 then
msgbox("密码不能为空,或长度超过12")
reg_form.pass.focus()
exit function
end if

if (reg_form.pass2.value="") or len(reg_form.pass.value)>12 then
msgbox("密码不能为空,或长度超过12")
reg_form.pass2.focus()
exit function
end if

if (reg_f