//校验用户名必须是:5-50个字符(包括小写字母、数字、下划线、中文),一个汉字为两个字符。 function bytes(str){ if(typeof(str)!='string'){ str = str.value; } var len = 0; for(var i = 0; i < str.length; i++){ if(str.charCodeAt(i) > 127){ len++; } len++; } return len; } function chkstr(str){ if(typeof(str)!='string'){ str = str.value; } for(var i = 0; i < str.length; i++){ if (!str.substr(i,1).match(/^\w+$/ig)){//str.charCodeAt(i) < 127 && return false; } } return true; } function checkItem(itm){ if (bytes(itm) < 5 || bytes(itm) > 50){ alert("请正确输入用户名,长度应该为5-50个字符"); return false; }else if (!chkstr(itm)){ alert("请正确输入用户名,5-50个字符(包括小写字母、数字、下划线)");//中文 return false; } return true; } function myChickEmail(txt){ var str= txt.value; if (str!=""){ if (!checkEmail(str)){ alert("请输入正确的Email地址!"); txt.focus(); txt.select(); return false; } } return true; } //校验密码不能全部是字母或数字或符号 //调用方式:onblur="passwordCheck1(this)" function passwordCheck1(item){ var passwordTemp = item.value; var flag = ""; var count = 0; for(var i = 0; i < passwordTemp.length; i++){ if ((passwordTemp.charCodeAt(i) >= 65 && passwordTemp.charCodeAt(i) <= 90) || (passwordTemp.charCodeAt(i) >= 97 && passwordTemp.charCodeAt(i) <= 122)){ flag = "isAllChar"; count++; }else{ flag = ""; } } if(flag == "isAllChar" && count == passwordTemp.length){ errorMessage("密码不能全部是字母,请正确输入密码"); item.focus(); return false; } flag = ""; count = 0; for(var i = 0; i < passwordTemp.length; i++){ if ((passwordTemp.charCodeAt(i) >= 48 && passwordTemp.charCodeAt(i) <= 57)){ flag = "isAllNumber"; count++; } } if(flag == "isAllNumber" && count == passwordTemp.length){ errorMessage("密码不能全部是数字,请正确输入密码"); item.focus(); return false; } flag = ""; count = 0; for(var i = 0; i < passwordTemp.length; i++){ if (passwordTemp.charCodeAt(i) < 48 || (passwordTemp.charCodeAt(i) > 57 && passwordTemp.charCodeAt(i) < 65) || (passwordTemp.charCodeAt(i) > 90 && passwordTemp.charCodeAt(i) < 97) || passwordTemp.charCodeAt(i) > 122){ flag = "isAllSign"; count++; } } if(flag == "isAllSign" && count == passwordTemp.length){ errorMessage("密码不能全部是符号,请正确输入密码"); item.focus(); return false; } } //检查登陆用户名不能为中文 function checkLogonUserName(txt){ if(!checkItem(txt)){ txt.focus(); return false; } return true; }