<!-- Begin

/*
NAME: validate.js

DESCRIPTION: Validates submitted values using <cfform> and <cfinput>. Can validate the following formats:
	checkemail   - Email 
	checkzip     - Zip (US)
	checkexpdate - Credit Card Expiration Date (mm/yyyy)
	checkphone   - Phone (US)

SYNTAX:

<cfform action="myaction" method="post">
<cfinput type="text" name="email" value="" onvalidate="checkemail" message="your validation message">
</cfform>

AUTHOR: Michael S. McKellip (msmckellip@herff-jones.com) 20-Apr-2000					
*/

function checkemail(form_object,input_object,object_value) {
// Checks if the e-mail address is valid.
	var emailPat = /^(\".+\"|[a-z\d]\w*([\-\.]\w+)*)@(\d{1,3}(\.\d{1,3}){3}|[a-z\d][\w-]*(\.[a-z\d][\w-]*)*\.[a-z]{2,5})$/i;
	var matchArray = object_value.match(emailPat);
	if (matchArray == null) {
		return false;
	}
// Make sure the IP address domain is valid.
	var IPArray = matchArray[3].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if (IPArray != null) {
		for (var i = 1; i <= 4; i++) {
			if (IPArray[i] > 255) {
				return false;
      		}
   		}
	}
	return true;
}

function checkzip(form_object,input_object,object_value) {
// Check if zip is valid. Must follow the "5" or "5+4" format.
	var zipPat = /^\d{5}$|\d{5}[\s\-]?\d{4}$/;
	var matchArray = object_value.match(zipPat);
	if (matchArray == null) {
		return false;
	}
	return true;
}

function checkexpdate(form_object,input_object,object_value) {
// Check validity of credit card expiration format. Requires date to be in the format mm/yyyy.
	var expdatePat = /^(\d{2})\/(\d{4})$/;
	var matchArray = object_value.match(expdatePat);
	if (matchArray == null) {
		return false;
	}
// Date passed test as valid format. Now check to make sure it is not expired.
	var curDate = new Date();
	var curMonth = curDate.getMonth() + 1;
	var curYear = curDate.getFullYear();
	
	if (matchArray[1] < 1 || matchArray[1] > 12) {
		return false;
	}
	
	if ((matchArray[1] < curMonth && matchArray[2] == curYear) || matchArray[2] < curYear) {
		return false;
	}
	
	return true;
}

function checkphone(form_object,input_object,object_value) {
/* Check validity of phone number. Must include area code and be 10 digits. Valid formats include xxx-xxx-xxxx, (xxx) xxx-xxxx, xxx.xxx.xxxx, xxx xxx xxxx */
	var phonePat = /^\(?(\d{3})\)?[\s\-\.]?(\d{3}[\s\-\.]?\d{4})$/;
	var matchArray = object_value.match(phonePat);
	if (matchArray == null) {
		return false;
	}
	return true;

}
//  End -->
