日期:2014-05-17 浏览次数:20659 次
<asp:ImageButton ID="imgRegister" runat="server" ImageUrl="Images/qdzc.gif" OnClientClick="return checkForm()" OnClick="imgRegister_Click" />
function checkForm() { if (checkUserName() && checkPass() && checkEmail() && chkMobile() && chkUName()) { return true; } else { return false; } } //用户名非空+长度+合法性验证 function checkUserName() { var name = document.getElementById("userid"); if (name.value == "") { alert("请输入登录名"); name.focus(); return false; } if (name.value.length < 4 || name.value.length > 16) { alert("登录名输入的长度4-16个字符"); name.select(); return false; } for (var i = 0; i < name.value.length; i++) { var charTest = name.value.toLowerCase().charAt(i); if ((!(charTest >= '0' && charTest <= '9')) && (!(charTest >= 'a' && charTest <= 'z')) && (charTest != '_')) { alert("用户名包含非法字符,只能包括字母,数字和下划线"); name.select(); return false; } } return true; } //密码非空+长度+密码确认验证 function checkPass() { var pass = document.getElementById("txtPass"); var rpass = document.getElementById("txtRPass"); if (pass.value == "") { alert("密码不能为空"); pass.focus(); return false; } if (pass.value.length < 6 || pass.value.length > 16) { alert("密码长度为6-16个字符"); pass.select(); return false; } if (rpass.value != pass.value) { alert("确认密码与密码输入不一致"); rpass.select(); return false; } return true; } //电子邮件验证 function checkEmail() { var strEmail = document.getElementById("txtEmail"); if (strEmail.value.length == 0) { alert("电子邮件不能为空!"); strEmail.focus(); return false; } if (strEmail.value.indexOf("@", 0) == -1) { alert("电子邮件格式不正确\n必须包含@符号!"); strEmail.select(); return false; } if (strEmail.value.indexOf(".", 0) == -1) { alert("电子邮件格式不正确\n必须包含.符号!"); strEmail.select(); return false; } return true; } //手机中号码验证 String.prototype.Trim = function() { var m = this.match(/^\s*(\S+(\s+\S+)*)\s*$/); return (m == null) ? "" : m[1]; } String.prototype.isMobile = function() { return (/^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/.test(this.Trim())); } String.prototype.isTel = function() { //"兼容格式: 国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)" //return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.te