﻿// JavaScript Document
var cForm = {patter:null,ctrl:true,flg:null,lgname:function(textBox){
	var mlgname = textBox.value;
	var ec = true;
	if(mlgname.length>=5 && mlgname.length <= 16){
		cForm.patter = "^[a-zA-Z]+"
		cForm.flg ="img"
		if(regex(cForm.patter,mlgname,cForm.flg)){
			cForm.patter ="^\\w{5,16}$"
			cForm.flg = "img"
			if(!regex(cForm.patter,mlgname,cForm.flg)){
				alert("\n\n用户名只能包含字母、数字、下划线");
				ec = false;
			}
		}
		else{
			alert('用户名必须以字母开头')
			ec= false;
		}
	}
	else{
		ec = false
		alert('\n\n用户名最小 5 位  最在 26 位\n\n您输入的位数不够或超出范围');
	}
	cForm.sign(ec,textBox)
	return ec;
},
mail:function(textBox){
	var mmail = textBox.value
	var ec = true;
	if(mmail.length > 5 && mmail.length <=50){
		//cForm.patter ="^\\w[\\w|\.]{4,}@[a-z0-9_-]{2,}(\.){1}\\w{2,}[\\.\\w]*$"
		cForm.patter = "^\\w[\\w|\.]{2,}@\\w{2,}\\.\\w{2,5}";
		cForm.flg = "ig"
		if(!regex(cForm.patter,mmail,cForm.flg))
		{
			alert( '邮件地址格式错误');
			ec = false;
		}
	}
	else{
		cForm.errInfor+= '电子邮件不符合最基本的标准';	
		ec = false;
	}
	cForm.sign(ec,textBox)
	return ec
},
tel:function(textBox){
	var mtel = textBox.value
	var ec = true
	cForm.patter ="^0[1-9]{3}-{0,1}[0-9]{7}$|^0[1-9]{2}-{0,1}[0-9]{8}$"
	if(!regex(cForm.patter,mtel,'')){
		ec  = false;
	}
	return ec;
},
mob:function(textBox,textBox2){
	var mmob = textBox.value
	var ec = true;
	cForm.patter ="^1(3|5)[0-9][0-9]{8}$"
	if(!regex(cForm.patter,mmob,'')){
		alert('手机或电话必须输入一项:\n\n电话的格式为\n\n区号-号码\n如021-32030000 \n或0351-4453000');
		ec = false;
	}
	cForm.sign(ec,textBox)
	cForm.sign(ec,textBox2)
	return ec;
},
sign:function(ec,textBox){/////错误标记
	if(ec){
		textBox.style.borderWidth="1px";
		textBox.style.borderColor="green";
		textBox.style.borderStyle="solid";
	}
	else{
		textBox.style.borderWidth="1px";
		textBox.style.borderColor="red";
		textBox.style.borderStyle="solid";
		cForm.ctrl = ec;
	}
}
}
function regex(p,v,f){
	var newregex = new RegExp(p,f)
	return newregex.test(v)
}
function chlg(f){
	var flg = true;
	if(cForm.lgname(f.username) && f.userpwd.value!="")
		f.submit()
}
/*

*/