<!--
function GenericValidator() {

}

/// <summary>
/// Check the text either empty, blank or null
/// static method for the GenericValidator
/// </summary>
GenericValidator.isBlankOrNull = function(text) {
	var bEmpty = false;

	if (text == null || text == undefined) {
		bEmpty = true;
	} else {
		if (typeof(text) == "string") {
			bEmpty = (text.replace(/ /g, "").length == 0) ? true : false;
		} else {
			bEmpty = false;
		}
	}

	return (bEmpty);
}

/// <summary>
/// A function to check the provided string is int or not
/// </summary>
GenericValidator.isInt = function(str) {
	try {
		parseInt(str);
		return true;
	} catch (e) {
		return false;
	}
}

/// <summary>
/// A function to check the provided string is correct email address or not
/// </summary>
GenericValidator.isEmail = function(str) {
	var strInfo = str.split("@");

	//-- check at most one @ is exist
	if (strInfo.length > 2) return false;
	if (strInfo.length < 2) return false;

	//-- start str validation
	var user = strInfo[0];
	var domain = strInfo[1];
	var userFormat = /[\s\/\\\*\+\?\|\(\)\[\]\{\}~!@#$%^&=;\'\"<>:]/;
	var domainFormat = /[\s\/\\\*\+\?\|\(\)\[\]\{\}~!@#$%^&=;\'\"<>:_]/;

	//-- check username haven't any illegal character
	if (user.match(userFormat) != null)
		return false;

	// @check at least the format of domain be XXXX.XXX
	if (domain.indexOf(".") == -1)
		return false;

	//-- check the top domain at least have 1 char and not more than 4 char
	if ((domain.substring(domain.lastIndexOf(".") + 1, domain.length).length > 4) || (domain.substring(domain.lastIndexOf(".") + 1, domain.length).length < 2))
		return false;

	//-- check the top level domain MUST be English character
	if (domain.substring(domain.lastIndexOf(".") + 1, domain.length).match(/[^A-Za-z]/) != null)
		return false;

	//-- check the domain havent any illegal character
	if (domain.match(domainFormat) != null)
		return false;

	return true;
}

/// <summary>
/// A function to check the provided string is correct date or not
/// </summary>
GenericValidator.isDate = function(str) {
	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Also separates date into month, day, and year variables
	var datePattern = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

	// To require a 4 digit year entry, use this line instead:
	// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		return false;
	}

	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];

	if (month < 1 || month > 12) { // check month range
		return false;
	}

	if (day < 1 || day > 31) {
		return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		return false
	}

	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			return false;
		}
	}

	return true;  // date is valid
}
//-->

