用户注册页面代码javascript验证Word下载.docx
《用户注册页面代码javascript验证Word下载.docx》由会员分享,可在线阅读,更多相关《用户注册页面代码javascript验证Word下载.docx(10页珍藏版)》请在冰点文库上搜索。
用户ID长度小于6位!
"
);
form.userid.focus();
returnfalse;
maxLength(userid,8))(
用户ID长度大于8位!
)
}
//判断用户名长度
minLength(username,6))
(
用户名长度小于6位!
form.username.focus();
maxLength(username,8))
用户名长度大于8位!
//判断口令长度
minLength(userpass,6))
口令长度小于6位!
form.userpass.focus();
maxLength(userpass,8))
口令长度大于8位!
//判断用户名和口令是否相同
if(username==userpass)
用户名和口令不能相等!
〃验证两次口令是否相同
if(userpass!
=userpass2)(
两次输入的口令不相同!
〃验证生日的格式是否正确
isDate(birthday))
生日的格式不正确!
form.birthday.focus();
//验证email的格式是否正确
isEmail(email))
Email格式不正确!
form.email.focus();
〃验证电话号码的格式是否正确
isDigital(phone))
电话号码的格式不正确"
form.phone.focus();
〃验证地址的长度是否正确
maxLength(address,50))
地址长度大于50位!
form.address.focus();
returntrue;
//验证是否是空
functionisNull(str)
if(str.length==0)
else
〃验证是否满足最小长度
functionminLength(str,length)
if(str.length>
=length)
//判断是否满足最大长度
functionmaxLength(str,length)
if(str.length<
//判断是否是数字
functionisDigital(str)
for(i=0;
i<
str.length;
i++)
//允许使用连字符
if(str.charAt(i)>
='
0'
&
str.charAt(i)<
9'
||str.charAt(i)=="
-"
i!
=0&
=str.length-1)continue;
//判断是否是整数
functionisNumber(str)
//如果要判断小数,需要判断小数点
i==0)continue;
//判断是否是日期,日期的格式为1988-1-1
functionisDate(date)
//查找分隔符
indexl=date.indexOf("
//如果分隔符不存在,则不是合法的时间
if(index1==-1)
//获取时间中的年
year=date.substring(0,index1);
//获取时间中的剩下部分
date=date.substring(index1+1);
//查找第二个分隔符
index1=date.indexOf("
//如果不存在第二个分隔符,则不是合法的时间
//获取时间中的月份
month=date.substring(0,index1);
//获取时间中的日
day=date.substring(index1+1);
//判断是否是数字,如果不是则不是合法的时间
if(isNumber(year)&
isNumber(month)&
isNumber(day))
//判断基本范围
if(year<
1900||year>
9999||month<
1||month>
12||day<
1)
//判断31天的月
if((month==1||month==3||month==5||month==7
||month==8||month==10||month==12)&
day>
31)returnfalse;
//判断30天的月
if((month==4||month==6||month==9||month==11)
30)returnfalse;
//如果是2月,判断是否为润年
if(month==2)
if(year%400==0||(year%4==0&
year%100!
=0))
if(day>
29)
}else
28)
//判断是否是Email
functionisEmail(email)
if(email.length==0)
index1=email.indexOf('
@'
index2=email.indexOf('
.'
if(index1<
1//@符号不存在,或者在第一个位置
||index2<
1//.符号不存在,或者在第一个位置
||index2-index1<
2//.在@的左边或者相邻
||index2+1==email.length)//.符号后面没有东西
returnfalse
/script>
html>
head>
title>
注册界面<
/title>
/head>
body>
h2align="
center"
请注册<
/h2>
formaction="
register_confirm.jsp"
method="
get"
isValidate(form1)"
tablealign="
tr>
td>
用户ID:
/td>
inputtype="
text"
value="
zhangsan”>
6—8位<
例>
用户名:
/tr>
口令:
password"
确认口令:
生日:
text”>
格式为:
1988-1-1<
学历:
radio"
专科"
专科
本科"
checked>
本科
硕士研究生"
硕士研究生
博士研究生"
博士研究生
其他"
其他<
地区:
select>
optionvalue="
华东"
华东<
/option>
华南"
华南<
华北"
华北<
东d匕"
selected>
东d匕<
东南"
东南<
西南"
西南<
西d匕"
西d匕<
华中"
华中<
/select>
E-mail:
地址:
电话:
备注:
textarearows="
8"
cols="
40"
1222222"
/textarea>
reset"
重置"
submit"
提交"
table>
/form>
/body>
/html>