function getLen(str){
return str.replace(/[^\x00-\xff]/g,"aa").length;
}
function testSame(str){
var flag = true;
var m = str[0];
for(var i=0;i<str.length;i++){
if(m!=str[i]){
flag = false;
}
}
return flag;
}
window.onload=function(){
var aInput = document.getElementsByTagName("input");
var name = aInput[0];
var pass = aInput[1];
var passTwo = aInput[2];
var mess = document.getElementsByTagName("p");
var name_mess = mess[0];
var pass_mess = mess[1];
var passTwo_mess = mess[2];
var count_mess = document.getElementById("count");
var aEm = document.getElementsByTagName("em");
var em1 = aEm[0];
var em2 = aEm[1];
var em3 = aEm[2];
var nameLen = 0;
var re = /[^\w\u4e00-\u9fa5]/g;
//会员名的要求:5-25个字符,一个汉字为两个字符,推荐使用中文会员名,
//汉字,数字,下划线,字母(不区分大小写)
//会员名输入框获取焦点
name.onfocus = function(){
name_mess.style.display = "block";
name_mess.innerHTML = '<i class="ati"></i>5-25个字符,一个汉字为两个字符,推荐使用中文会员名';
}
//会员名输入字符变化
name.onkeyup = function(){
count_mess.style.visibility = "visible";
nameLen = getLen(this.value);
count_mess.innerHTML = nameLen +"个字符";
if(nameLen == 0){
count_mess.style.visibility = "hidden";
}
}
//会员名输入框失去焦点
name.onblur = function(){
//检查会员名是否正确
//含有非法字符
if(re.test(this.value)){
name_mess.innerHTML = '<i class="err"></i>名字含有非法字符,不合法!';
}
//不能为空
else if(this.value ==""){
name_mess.innerHTML = '<i class="err"></i>不能为空!';
}
//长度小于6
else if(nameLen < 5){
name_mess.innerHTML = '<i class="err"></i>名字小于5个字符,不合法!';
}
//长度大于25
else if(nameLen >25){
name_mess.innerHTML = '<i class="err"></i>名字大小于25个字符,不合法!';
}
//正确
else {
name_mess.innerHTML = '<i class="ok"></i>OK!';
}
}
//密码框获得焦点,显示提示内容
pass.onfocus = function(){
pass_mess.style.display = "block";
pass_mess.innerHTML = '<i class="ati"></i>6-16个字符请使用字母加数字或符号的组合密码,不能单独使用字母、数字或符号。';
}
//密码输入字符变化,em会变化
pass.onkeyup = function(){
//密码长度大于5的时候为中,大于10为强
if(this.value.length>5){
em2.className="active";
passTwo.removeAttribute("disabled");
passTwo_mess.style.display="block";
}else
{
em2.className="";
passTwo.setAttribute("disabled");
passTwo_mess.style.display="none";
}
if(this.value.length>10){
em3.className="active";
}else {
em3.className="";
}
}
//会员名输入框失去焦点
pass.onblur = function(){
var reg1 = /[^0-9]/g;
var reg2 = /[^a-zA-Z]/g;
//密码不能为空
if(this.value==""){
pass_mess.innerHTML = '<i class="err"></i>密码不能为空!';
}
//长度应为6-16个字符
else if(this.value.length<6 || this.value.length>16){
pass_mess.innerHTML = '<i class="err"></i>长度应为6-16个字符!';
}
//不能使用相同的字符
else if(testSame(this.value)){
pass_mess.innerHTML = '<i class="err"></i>不能使用相同的字符!';
}
//不能全部为数字
else if(!reg1.test(this.value)){
pass_mess.innerHTML = '<i class="err"></i>不能全为数字!';
}
//不能全部为字母
else if(!reg2.test(this.value)){
pass_mess.innerHTML = '<i class="err"></i>不能全为字母!';
}
else {
pass_mess.innerHTML = '<i class="OK"></i>OK!';
}
//OK
}
passTwo.onblur = function(){
if(this.value != pass.value){
passTwo_mess.innerHTML = '<i class="err"></i>两次输入的密码不一致!';
}
else {
passTwo_mess.innerHTML = '<i class="OK"></i>OK!';
}
//OK
}
}