/**
* 去掉前后空格
*/
function Trim(str)
{
  return str.replace(/(^\s*)|(\s*$)/g,"");
}

/**
* 判断是否为空
*/

function checkHasValue(checkStr)
{
    if (Trim(checkStr).length == 0){
        
        return false;
    }
    return true;
}


/**
* 判断是否是数字
*
*/
function checkNumber(checkStr)
{

	 if (!checkStr.match("^[0-9]*[1-9][0-9]*$") && !checkStr.match("^((-\\d+)|(0+))$") && !checkStr.match("^\\d+(\\.\\d+)?$") && !checkStr.match("^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$")){
		 
         return false;
	 }
     return true;
}

/**
* 判断是否整数
*/
function checkInt(checkStr)
{
     
     if (!checkStr.match("^-?\\d+$")){
         
         return false;
	 }
     return true;
}

/**
* 判断是否正整数
*/
function checkPInt(checkStr)
{
     
     if (!checkStr.match("^[1-9]+[0-9]*$")){
         
         return false;
     }
     return true;
}

/**
* 判断是否非负整数
*/
function checkNotNInt(checkStr){
     
     if (!checkStr.match("^[0-9]+$")){
     
         return false;
     }
     return true;
}

/**
* 判断日期格式     YYYY-MM-DD
*/
function  checkDate(strDate){
     var  strSeparator  =  "-";  //日期分隔符
     var  strDateArray;
     var  intYear;
     var  intMonth;
     var  intDay;
     var  boolLeapYear;

     strDateArray  =  strDate.split(strSeparator);

     if	(strDateArray.length!=3){
         
         return  false;
     }

     intYear  =  parseInt(strDateArray[0],10);
     intMonth =  parseInt(strDateArray[1],10);
     intDay   =  parseInt(strDateArray[2],10);

     if(isNaN(intYear)  ||isNaN(intMonth)  || isNaN(intDay)){
               
               return  false;
     }
     if(intMonth>12  ||intMonth<1){
               
               return  false;
     }
     if((intMonth==1  ||intMonth==3  ||intMonth==5  ||intMonth==7  ||intMonth==8  ||intMonth==10  ||intMonth==12)&&(intDay>31  ||intDay<1)){
               
               return  false;
     }
     if((intMonth==4  ||intMonth==6  ||intMonth==9  ||intMonth==11)&&(intDay>30  ||intDay<1)){
               
               return  false;
     }
     if(intMonth==2){
           if(intDay<1){
               
                   return  false;
           }
           boolLeapYear  =  false;
           if((intYear%100)==0){
                 if((intYear%400)==0)  boolLeapYear  =  true;
           }
           else{
                 if((intYear%4)==0)  boolLeapYear  =  true;
           }

           if(boolLeapYear){
                 if(intDay>29){
               
                       return  false;
               }
           }
           else{
                 if(intDay>28){
                  
                       return  false;
                 }
           }
     }
     return  true;
}

/**
* 电话号码验证
*/
function checkPhone(checkStr){
    checkOkStr = "^[0-9][0-9\-]{5,20}$";
    if (!checkStr.match(checkOkStr)){
        
        return false
    }
	if (!checkStr.match("-")){
        
        return false
    }
    return true;
}


/**
* 手机号码验证
*/
function checkMobile(checkStr)
{
	if (checkStr.length!=11){
	     
		return false
	}
	else if (checkStr.substring(0,2)!="13"){
		
		return false;
	}
	else if (isNaN(checkStr)){
	     
		return false;
	}

	return true;
}

/**
* 邮政编码判断
*/
function isZipCode(checkStr){
	if (!isEmpty(checkStr)){
		if(!isCharsInBag (checkStr, "0123456789")){
	        
			return false;
		}
		if (checkStr.length==6){
	        
			return true;
	        
		}else{
	        
			return false;
		}
	} else {
	return true;
	}
}


/**
* Email检测
*/
function checkEmail(checkStr){
    if (!checkStr.match("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$")){
		
		return false;
	}
    return true;
}

/**
* Url检测
*/
function checkUrl(checkStr){
    if (!checkStr.match("^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$")){
        
        return false;
    }
    return true;
}

/**
* 用户名检测
*/
function checkUserName(checkStr){
    if (!checkStr.match("^[\\w-]+$")){
        
        return false;
    }
    return true;
}

/**
* 密码检测
*/
function checkPassword(checkStr){
    if (!checkStr.match("^[^\r\t\n\32]+$")){
		
        return false;
    }
    return true;
}


/**
*检查文件后缀
*/
function checkFileExt(checkStr , arrExt){
	sflag = false;
	for (i = 0 ; i < arrExt.length ; i++){
		okStr = ".+[.]+" + arrExt[i] + "+$";
		if (checkStr.match(okStr)){
			sflag = true;
			break;
		}
	}
	if (sflag == false){
		return false;
	}
	return sflag;

}


/**
* 检查图片文件后缀
*/
function checkImageExt(checkStr){
	var sflag = false;
	var arrExt = new Array("jpg" , "JPG" , "gif" , "GIF" , "png" , "PNG");
	sflag = checkFileExt(checkStr , arrExt);
	return sflag;
}//end function




