JS必填字段验证

[code=JScript]
<SCRIPT LANGUAGE="JavaScript">
<!--
function check()
{
if(checkspace(document.userinfo.username.value)) {
document.userinfo.username.focus();
alert("用户名不能为空,请重新输入!");
return false;
}
if(checkspace(document.userinfo.username.value) || document.userinfo.username.value.length < 2) {
document.userinfo.username.focus();
alert("用户名长度不能小于2,请重新输入!");
return false;
}
if(checkspace(document.userinfo.identify.value) || document.userinfo.identify.value.length < 15) {
document.userinfo.identify.focus();
alert("身份证号码长度不能小于15位,请重新输入!");
return false;
}
if(checkspace(document.userinfo.identify.value) || document.userinfo.identify.value.length > 18) {
document.userinfo.identify.focus();
alert("身份证号码长度不能大于18位,请重新输入!");
return false;
}
if(checkspace(document.userinfo.UserPassword.value) || document.userinfo.UserPassword.value.length < 6) {
document.userinfo.UserPassword.focus();
alert("密码长度不能小于6,请重新输入!");
return false;
}
if(document.userinfo.UserPassword.value != document.userinfo.UserPassword1.value) {
document.userinfo.UserPassword.focus();
document.userinfo.UserPassword.value = '';
document.userinfo.UserPassword1.value = '';
alert("两次输入的密码不同,请重新输入!");
return false;
}
if(document.userinfo.useremail.value.length!=0)
{
if (document.userinfo.useremail.value.charAt(0)=="." ||
document.userinfo.useremail.value.charAt(0)=="@"||
document.userinfo.useremail.value.indexOf( '@', 0) == -1 ||
document.userinfo.useremail.value.indexOf('.', 0) == -1 ||
document.userinfo.useremail.value.lastIndexOf("@")==document.userinfo.useremail.value.length-1 ||
document.userinfo.useremail.value.lastIndexOf(".")==document.userinfo.useremail.value.length-1)
{
alert("Email地址格式不正确!");
document.userinfo.useremail.focus();
return false;
}
}
else
{
alert("Email不能为空!");
document.userinfo.useremail.focus();
return false;
}
}
function checkspace(checkstr) {
var str = '';
for(i = 0; i < checkstr.length; i++) {
str = str + ' ';
}
return (str == checkstr);
}
//-->
</script>
[/code]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值