Validator = function(value){
	
	this.value = value;
	
	//--Check if value (string or array) is empty
	this.isEmpty = function(){
		return (this.value === null) ? true : (this.value.length == 0);
	}
	//--Check if value is integer
	this.isInteger = function(){
		if( this.isEmpty() ){
			return false;
		}
		var v = this.value * 0;
		return v == 0;
	}
	
	//--Check if value is string
	this.isString = function(){
		return !this.isEmpty();
	}
	
	this.isStringInLength = function(min, max){
		if( this.value.length < min || this.value.length > max ){
			return false;
		}
		return true;
	}
	
	//--Check if integer in range
	this.isIntegerInRange = function(min, max){
		if( !this.isInteger() ){
			return false;
		}
		if( this.value < min || this.value > max ){
			return false;
		}
		return true;
	}
	
	//--Check if value is minute : integer from 0 to 59
	this.isMinute = function(){
		return this.isIntegerInRange(0,59);
	}
	
	//--Check if value is second : integer from 0 to 59
	this.isSecond = function(){
		return this.isIntegerInRange(0,59);
	}
	
	//--Check if value is hour : integer from 0 to 23
	this.isHour = function(){
		return this.isIntegerInRange(0,23);
	}
	
	//--Check if value is email
	this.isEmail = function(){
		if (this.isEmpty()) {
			return false;
		}
		
		var reEmail = new RegExp('^(_)?[a-z0-9]((_|-|\\.)?[a-z0-9])*@([a-z0-9]((_|-|\\.)?[a-z0-9])*\\.)+[a-z]{2,4}$', 'i');
		if (reEmail.test(this.value)) {
			return true;
		}
		return false;
	}
	
	//--Check if value is host
	this.isHost = function(){
		if (this.isEmpty()) {
			return false;
		}
		
		var reHost = new RegExp('^([a-z0-9]([_-]?[a-z0-9])*\\.)+[a-z]{2,4}$', 'i');
		if (reHost.test(this.value)) {
			return true;
		}
		return false;
	}
	
	//--Check if value is ipv4
	this.isIPv4 = function(){
		if (this.isEmpty()) {
			return false;
		}
		
		var arr = this.value.split('.');
		if (arr.length != 4) {
			return false;
		}
		
		for (var i=0; i<arr.length; i++) {
			var v1 = new Validator(arr[i]);
			if (!v1.isIntegerInRange((i==0 ? 1 : 0), 255)) {
				return false;
			}
		}
		return true;
	}
	
	//--Check if value is port
	this.isPort = function(){
		if (this.isEmpty()) {
			return false;
		}
		
		if (!this.isInteger()) {
			return false;
		}
		return (0 < parseInt(this.value,10) && parseInt(this.value,10) < 65535);
	}
}
