﻿// JavaScript Document
function Validate(){
	
/*验证空*/
this.required=function(str){
	if(str==null){
		return false;
	}
	str=str.replace(/(^\s*)|(\s*$)/, "");
	if(str.length==0){
		return false;
	}
	return true;
}

/*验证长度*/
this.Length=function(str,minLength,maxLength){
	if(!required(str)){
		return false;
	}
	if(str.length<minLength||str.length>maxLength){
		return false;
	}
	return true;
}
this.maxLength=function(str,length){
	if(!required(str)){
		return false;
	}
	if(str.length>length){
		return false;
	}
	return true;
}
this.minLength=function(str,length){
	if(!required(str)){
		return false;
	}
	if(str.length<length){
		return false;
	}
	return true;
}
/*验证email*/
this.mail=function(mail){
	if(!required(mail)){
		return false;
	}
	var pattern=/^[a-zA-Z0-9\._]+@[a-zA-Z0-9\._]+\.\w+$/;
	return pattern.test(mail);
}

/*比较*/
this.compare=function(str1,str2){
	if(!required(str1)||!required(str2)){
		return false;
	}
	if(str1!=str2){
		return false;
	}
	return true;
}
/*数字*/
this.isInt=function(str){
	if(!required(str)){
		return false;
	}
	var pattern=/^\d+$/;
	return pattern.test(str);
}

function required(str){
	if(str==null){
		return false;
	}
	str=str.replace(/(^\s*)|(\s*$)/, "");
	if(str.length==0){
		return false;
	}
	return true;
}
}
