
// JavaScript Document;

// phone validation:   var phoneRE = /^\(\d\d\d\) \d\d\d-\d\d\d\d$/;
// phone validation:   var phoneRE = /^\(\d{3}\) \d{3}-\d{4}$/;

// SSN (proper format only) : ^\d{3}-\d{2}-\d{4}$
// SSN (with or without dashes) : ^(\d{3}-\d{2}-\d{4})|(\d{3}\d{2}\d{4})$

/*
 * isEmpty() : Data Validation
 * @param string, number - Make sure some type of data has been entered
 * @return boolean : True if data has been given. It is False otherwise.
 * 
 * @TESTED AND WORKING
*/

function hasData(data) {
	if (data === "") {
		return false;	
	} else {
		return true;	
	}
}


/*
 * isAlphaOnly() : Alpha Chars Validation
 * @param string : A string only
 * @return boolean : True if the string contains alphabetical chars only. It is False otherwise.
 * 
 * @TESTED AND WORKING
*/

function isAlphaOnly(data) {
	var regEx = /([0-9][^a-zA-Z])|([^a-zA-Z][0-9])$/;
	if (!regEx.test(data)) {
		return false;	
	} else {
		return true;	
	}
}


/*
 * isNumericOnly() : Alpha Chars Validation
 * @param string : A string only
 * @return boolean : True if the string contains numeric chars only. It is False otherwise.
 * 
 * @TESTED AND WORKING
*/

function isNumericOnly(data) {
	var regEx = /^([0-9]{1,})$/;
	if (!regEx.test(data)) {
		return false;	
	} else {
		return true;	
	}
}

/*
 * isAlphaNumeric() : Alpha Chars Validation
 * @param string : A string only
 * @return boolean : True if the string contains numeric chars only. It is False otherwise.
 * 
 * @TESTED AND WORKING
*/

function isAlphaNumeric(data) {
//	var regEx = /^([^a-z]{1,})|([^A-Z]{1,})([^0-9]{1})$/;
	//var regEx = /([^a-zA-Z0-9])([a-zA-Z0-9*][^{0,3}])$/;
	var regEx = /^([\w]{3,})$/;
	
	if (!regEx.test(data)) {
		return false;	
	} else {
		return true;	
	}
}


/*
 * isEmail() : Email Validation
 * @param string : A string only
 * @return boolean : True if the string contains an '@', '.', and between 2 to 4 chars after period. It is False otherwise.
 * 
 * @TESTED AND WORKING
*/

function isEmail(data) {
	var regEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!regEx.test(data)) {
		return false;	
	} else {
		return true;	
	}
}


/*
 * isPhoneNumer() : Email Validation
 * @param string : A string only
 * @return boolean : True if the string contains two '-', and proper phone format of ###-###-####. It is False otherwise.
 * 
 * @TESTED AND WORKING
*/

function isDashedPhoneNumber(data) {
	var regEx = /^([0-9]{3})+(\-)+([0-9]{3})+(\-)+([0-9]{4})$/;
	if (!regEx.test(data)) {
		return false;	
	} else {
		return true;	
	}
}

/*
 * isPhoneNumer() : Email Validation
 * @param string : A string only
 * @return boolean : True if the string contains two '.', and proper phone format of ###-###-####. It is False otherwise.
 * 
 * @TESTED AND WORKING
*/

function isDottedPhoneNumber(data) {
	var regEx = /^([0-9]{3})+(\.)+([0-9]{3})+(\.)+([0-9]{4})$/;
	if (!regEx.test(data)) {
		return false;	
	} else {
		return true;	
	}
}


/*
 * isRadioChecked() : Radio Button (Single or Group) Validation
 * @param string : A string only
 * @return boolean : True if selectedCount is equal to 1. It is False otherwise.
 * 
 * @TESTED AND WORKING
*/

function isRadioChecked(target) {
	var selectedCount = -1;
	
	for (var i=0; i<target.length; i++) {
		if (target[i].checked == true) {
			selectedCount = 1;
		}
	}
	
	if (selectedCount != 1) {
		return false;
	} else {
		return true;	
	}
}

/*
 * dropdownHasValue(val) : Dropdown (Single only) Validation
 * @param string : A string only - drowpdown id to validate
 * @return boolean : True if the dropdown has a value and/or is not "null"
 * 
 * @TESTED AND WORKING
*/

function dropdownHasValue(val) {
    if (val == "" || val == "null") {
        return false;
    } else {
        return true;
    }
}

/*
 * isBoxChecked() : Checkboxn (Single only) Validation
 * @param string : A string only - formName to validate
 * @param string : A string only - Checkbox in the formName to validate
 * @return boolean : True if the checkbox in the correct form is checked
 * 
 * @TESTED AND WORKING
*/

function isBoxChecked(target) {
    if (target.checked == false) {
		return false;
	} else {
		return true;	
	}
}

/*
 * isStringInCountRange(dataToCount, countToMatch) : Make sure the data has more than dataToCount 
 * @param string : A string only
 * @param array : A array only - a range [min, max] the char count must fall within or be equal too either min or max.
 * @return boolean : True if selectedCount is equal to 1. It is False otherwise
 * 
 * @TESTED AND WORKING
*/

function isStringInCountRange(dataToCount, numberRange) {
	var charCount = Number(dataToCount.length);
	
	if (charCount <= numberRange[0] || charCount >= numberRange[1]) {
		return false;
	} else {
		return true;
	}
}


/*
 * isNumInCountRange(dataToCount, numberRange) : Make sure the data has no more than the selected count 
 * @param tring/number : A string or number
 * @param array : A array only - a range [min, max] the number must fall within or be equal too either min or max.
 * @return boolean : True if selectedCount is equal to 1. It is False otherwise
 * 
 * @TESTED AND WORKING
*/

function isNumInCountRange(dataToCount, numberRange) {
	var charCount = String(Number(dataToCount)).length;
	
	if (Number(charCount) <= numberRange[0] || Number(charCount) >= numberRange[1]) {
		return false;
	} else {
		return true;
	}
}

/*
 * isStrExactLength(dataToCount, numberRange) : Make sure the data has no more than the selected count 
 * @param string: A string
 * @param number: A array only - a range [min, max] the number must fall within or be equal too either min or max.
 * @return boolean : True if selectedCount is equal to 1. It is False otherwise
 * 
 * @TESTED AND WORKING
*/

function isExactLength(dataToCount, numberToMatch) {
	var numToMatch = new RegExp('\\d{' + numberToMatch + '}', 'g');
	if (!numToMatch.test(dataToCount)) {
		return false;	
	} else {
		return true;	
	}
}

