注册检查

<script language="JavaScript">

 function isNumeric(strNumber) {
     return (strNumber.search(/^(-|/ + ) ? /d+(/. / d + ) ? $ / ) != -1);
 }
 // this function returns TRUE if a email address is right format 

 function isEmail() {
     var email = (regfrm.email.value);
     // valid format "a@b.cd" 
     invalidChars = " /;,:{}[]|*%$#!()`<>?";
     if (email == "") {
         alert("请输入Email地址!");
         regfrm.email.focus();
         return false;
     }
     for (var i = 0; i < invalidChars.length; i++) {
         badChar = invalidChars.charAt(i);
         if (email.indexOf(badChar, 0) > -1) {
             alert("Email地址输入不正确!");
             regfrm.email.focus();
             return false;
         }
     }
     atPos = email.indexOf("@", 1)
     // there must be one "@" symbol 
     if (atPos == -1) {
         alert("Email地址输入不正确!");
         regfrm.email.focus();
         return false;
     }
     if (email.indexOf("@", atPos + 1) != -1) {
         // and only one "@" symbol 
         alert("Email地址输入不正确!");
         regfrm.email.focus();
         return false;
     }
     periodPos = email.indexOf(".", atPos);
     if (periodPos == -1) {
         // and at least one "." after the "@" 
         alert("Email地址输入不正确!");
         regfrm.email.focus();
         return false;
     }
     // and at least one character between "@" and "." 
     if (atPos + 2 > periodPos) {
         alert("Email地址输入不正确!");
         regfrm.email.focus();
         return false;
     }
     if (periodPos + 3 > email.length) {
         alert("Email地址输入不正确!");
         regfrm.email.focus();
         return false;
     }
     return true;
 }
 //function for check tel.no 

 function istel(test) {
     var tel = test;
     var validchars = "-()1234567890 ";
     if (tel.length == 0) {
         alert("请输入电话号码!");
         regfrm.phone.focus();
         return false;
     }
     for (i = 0; i < tel.length; i++) {
         telchar = tel.charAt(i);
         if (validchars.indexOf(telchar, 0) == -1) {
             alert("电话号码输入不正确!");
             regfrm.phone.focus();
             return false;
         }
     }
     return true;
 }

 function isDate(day, month, year) {
     // let's first check the user entered numbers 
     if (isNaN(Date.parse(month + "/" + day + "/" + year))) {
         return false;
     }
     var dd = parseInt(day, 10);
     // beware !! the computer handles monthes from 0 to 11. 
     var mm = parseInt(month, 10) - 1;
     var yy = parseInt('20' + year, 10);
     var date = new Date(yy, mm, dd);
     //let's now compare the user's entry with what the computer understand of it 
     if (dd != date.getDate() || mm != date.getMonth() || yy != date.getFullYear()) {
         return false;
     }
     return true;
 }

 function checkinput() {
     if (regfrm.checkbox.checked == false) {
         alert("您仔细阅读了《久游用户注册协议书》?");
         return false;
     }
     if (regfrm.username.value.length == 0) {
         alert("请输入用户名");
         regfrm.username.focus();
         return false;
     }
     var r, re = new RegExp("[A-Za-z0-9]+", "g");
     var s = regfrm.username.value;
     r = s.match(re);
     if (r == null || s.length != r[0].length) {
         alert("用户名只能为英数!");
         regfrm.username.focus();
         return false;
     }
     if (regfrm.username.value.length < 6) {
         alert("用户名必须大于6位");
         regfrm.username.focus();
         return false;
     }
     if (regfrm.username.value.length > 12) {
         alert("用户名不能超过12位");
         regfrm.username.focus();
         return false;
     }
     if (regfrm.nickname.value.length == 0) {
         alert("请输入昵称");
         regfrm.nickname.focus();
         return false;
     }
     if (regfrm.nickname.value.length > 16) {
         alert("昵称不能超过8个中文字符或者16个英文数字等组合");
         regfrm.nickname.focus();
         return false;
     }
     if (regfrm.password.value.length == 0) {
         alert("请输入密码");
         regfrm.password.focus();
         return false;
     }
     if (regfrm.password.value.length < 6) {
         alert("密码必须大于6位");
         regfrm.password.focus();
         return false;
     }
     if (regfrm.password.value.length > 20) {
         alert("密码不能超过20位");
         regfrm.password.focus();
         return false;
     }
     if (regfrm.password.value != regfrm.psw2.value) {
         alert("您两次输入的密码不一致");
         regfrm.password.focus();
         return false;
     }
     if (regfrm.secureCode.value.length == 0) {
         alert("请输入安全码");
         regfrm.secureCode.focus();
         return false;
     }
     if (regfrm.secureCode.value.length < 6) {
         alert("安全码必须大于6位");
         regfrm.secureCode.focus();
         return false;
     }
     if (regfrm.secureCode.value.length > 12) {
         alert("安全码不能超过12位");
         regfrm.secureCode.focus();
         return false;
     }
     if (regfrm.secureCode.value != regfrm.SerCode2.value) {
         alert("您两次输入的安全码不一致");
         regfrm.secureCode.focus();
         return false;
     }
     if (regfrm.idcard.value.length == 0) {
         alert("请输入身份证号码");
         regfrm.idcard.focus();
         return false;
     }
     var tempidcard = regfrm.idcard.value;
     if (regfrm.cardtype[1].checked == true) {
         if (regfrm.idcard.value.length != 18) {
             alert("身份证号码位数不对!");
             regfrm.idcard.focus();
             return false;
         }
         idcardlast = tempidcard.substring(17, 18);
         idcardfor = tempidcard.substring(0, 17);
         if (!isNumeric(idcardfor)) {
             alert("身份证号前17位必须是数字!");
             regfrm.idcard.focus();
             return false;
         }
         if (!isNumeric(idcardlast) && idcardlast != "x" && idcardlast != "X") {
             alert("身份证号最后一位必须是数字或者X!");
             regfrm.idcard.focus();
             return false;
         }
     }
     if (regfrm.cardtype[0].checked == true) {
         if (regfrm.idcard.value.length != 15) {
             alert("身份证号码位数不对!");
             regfrm.idcard.focus();
             return false;
         }
         idcardlast = tempidcard.substring(14, 15);
         idcardfor = tempidcard.substring(0, 14);
         if (!isNumeric(idcardfor)) {
             alert("身份证号前14位必须是数字!");
             regfrm.idcard.focus();
             return false;
         }
         if (!isNumeric(idcardlast) && idcardlast != "x" && idcardlast != "X") {
             alert("身份证号最后一位必须是数字或者X!");
             regfrm.idcard.focus();
             return false;
         }
     }
     if (isEmail() == false) {
         return false;
     }
     if (regfrm.realname.value.length == 0) {
         alert("请输入您的真实姓名");
         regfrm.realname.focus();
         return false;
     }
     if (regfrm.year.value.length == 0 || regfrm.year.value.length != 4) {
         alert("生日的年份必须为4位");
         regfrm.year.focus();
         return false;
     }
     if (isDate(regfrm.day.value, regfrm.month.value, regfrm.year.value) == false) {
         alert("您的生日输入有误");
         regfrm.year.focus();
         return false;
     }
     return true;
 }
</script>

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部