/**********************
		注册验证
	xupznb@gmail.com
		2007-6-21
***********************/

//检测是否空
function chk_air(val)
{  
	if(typeof( val)=='undefined' || val==null || val.length<1)
		return false;
	else
	{
        var patrn = /(^\s+|\s$)/g;   
        val=val.replace(patrn, ""); 
        if(val.length<1)
            return false;
		return true;
    }
}

//返回字符长度
function strLen(key){
	var l=escape(key),len
	len=l.length-(l.length-l.replace(/\%u/g,"u").length)*4
	l=l.replace(/\%u/g,"uu")
	len=len-(l.length-l.replace(/\%/g,"").length)*2
	return len
}

//是否一致
function issame(str1,str2)  
{  
	if(!chk_air(str1))
	{ return false;}
	if (str1==str2)  
	{return(true);}  
	else  
	{return(false);}  
}  

//是否数字
function chk_Num(str)
{return str.match(/\D/)==null}  

//判断是否是字符  true 全字符 false 含有汉字
function chk_allstr(val)
{
	return !(/[^\x00-\xff]/g.test(val)) ;
}

//邮箱格式验证
//函数名：chkemail     
//功能介绍：检查是否为Email Address     
//参数说明：要检查的字符串     
//返回值：0：不是 1：是     
function chkemail(a)     
{ var i=a.length;     
var temp = a.indexOf('@');     
var tempd = a.indexOf('.');     
if (temp > 1) {     
if ((i-temp) > 3){     
if ((i-tempd)>0){     
return 1;     
}     
    
}     
}     
return 0;     
}     

//数字格式验证
//函数名：fucCheckNUM     
//功能介绍：检查是否为数字     
//参数说明：要检查的数字     
//返回值：1为是数字，0为不是数字     
function fucCheckNUM(NUM)     
{     
var i,j,strTemp;     
strTemp="0123456789";     
if ( NUM.length== 0)     
return 0     
for (i=0;i<NUM.length;i++)     
{     
j=strTemp.indexOf(NUM.charAt(i));     
if (j==-1)     
{     
//说明有字符不是数字     
return 0;     
}     
}     
//说明是数字     
return 1;     
}  

//电话号码格式验证
//函数名：fucCheckTEL     
//功能介绍：检查是否为电话号码     
//参数说明：要检查的字符串     
//返回值：1为是合法，0为不合法     
function fucCheckTEL(TEL)     
{     
var i,j,strTemp;     
strTemp="0123456789-()# ";     
for (i=0;i<TEL.length;i++)     
{     
j=strTemp.indexOf(TEL.charAt(i));     
if (j==-1)     
{     
//说明有字符不合法     
return 0;     
}     
}     
//说明合法     
return 1;     
}    


/*检测帐号
 *返回 0 -- 空
 *返回 1 -- 长度不符合
 *返回 2 -- 有未允许的字符
 *返回 99-- 符合要求
*/
function chk_name(val,type)
{
	if(!chk_air(val))
		return 0;
	if(type==1)//帐号以数字、字母、_任意组合
	{
		if(strLen(val)>20||strLen(val)<4)
			return 1;
		if(!/^[a-zA-Z0-9_]*$/.test(val))
			return 2;
		return 99;
	}
}

/*检测密码
 *返回 0 -- 空
 *返回 1 -- 长度不符合
 *返回 2 -- 有未允许的字符
 *返回 99-- 符合要求
*/
function chk_pwd(val,type)
{
	if(!chk_air(val))
		return 0;
	if(type==1)//帐号以数字、字母、_任意组合
	{
		if(strLen(val)>20||strLen(val)<6)
			return 1;
		if(!/^[a-zA-Z0-9]*$/.test(val))
			return 2;
		return 99;
	}
}
      

