// trim functionality
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

// validation
function isEuroDate(val) {
	// the pattern to match
	// check euro date in the format of 'dd/mm/yyyy'
	//pattern = /(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))/
	// check euro date in the format of 'dd-mm-yyyy'
	pattern = /(((0[1-9]|[12]\d|3[01])-(0[13578]|1[02])-((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)-(0[13456789]|1[012])-((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])-02-((19|[2-9]\d)\d{2}))|(29-02-((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))/
	if (val.length > 0) {
		// the actually matching
		if (val.search(pattern) == -1) {
			return false
		}
		else {
			return true
		}
	}
}

function isInt(val) {
	// get the modulus: if it's 0, then it's an integer
	var myMod = val % 1
	
	if (myMod == 0) {
		return true
	} 
	else {
		return false
	}
}

function isEmail(val) {
	if (val.match(/^[a-zA-Z_0-9-'\+~]+(\.[a-zA-Z_0-9-'\+~]+)*@([a-zA-Z_0-9-]+\.)+[a-zA-Z]{2,7}$/)) {
		return true
		}
	else {
		return false
		}
}

function isZip(val) {
	if (val.match(/^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/)) {
		return true
		}
	else {
		return false
		}
}

function isMobile(val) {
	if (val.match(/^06[1-9]{1}[0-9]{7}$/)) {
		return true
		}
	else {
		return false
		}
}

function isPhone(val) {
	if (val.match(/^[0-9]{10}$/)) {
		return true
		}
	else {
		return false
		}
}
