for (var i=0; i < formatFields.length; i++) {
eval("var field = form." + formatFields[i]);
if (field) { // Make sure the field is found
// NOTE: THE TRIM JAVASCRIPT FUNCTION MUST BE INCLUDED
// NOTE: THE GETFIELDVALUE JAVASCRIPT FUNCTION MUST BE INCLUDED
var value = trim(getFieldValue(field));
var successes = formatSuccesses[i];
if (typeof(successes[0]) == "object") { // If it's an array
// Go through all the expressions and see if they all match and see if any match
var allMatched = true;
var anyMatched = false;
for (var x=0; x < successes.length; x++) {
var exp = new RegExp(successes[x], "gi");
var check = exp.test(value);
if ( !check ) { allMatched = false; }
if ( check ) { anyMatched = true; }
}
// If the developer said they all have to match and they didn't all match, return an error
if (formatMatchAllSuccesses[i] && !allMatched) {
alert(formatMessages[i]);
field.focus();
return false; // Return as soon as a failure is detected
}
// If none of them matched, it doesn't matter what the developer said, return an error
if ( !anyMatched ) {
alert(formatMessages[i]);
field.focus();
return false; // Return as soon as a failure is detected
}
} else { // The formatSuccesses entry is a single value, not an array
var exp = new RegExp(successes, "gi");
var check = exp.test(value);
if ( !check ) { // If that single expression didn't match the criteria (thus, a failure)
alert(formatMessages[i]);
field.focus();
return false; // Return as soon as a failure is detected
}
} // Ends the check to see if the format successes entry is an array or a single value
} // Ends the check to see if the field exists
} // Move on to the next field
return true; // If we got this far, everything worked
} // Ends the "areSuccessesPresent" function
function areFailuresPresent(form) {
for (var i=0; i < formatFields.length; i++) {
eval("var field = form." + formatFields[i]);
if (field) { // Make sure the field is found
// NOTE: THE TRIM JAVASCRIPT FUNCTION MUST BE INCLUDED
// NOTE: THE GETFIELDVALUE JAVASCRIPT FUNCTION MUST BE INCLUDED
var value = trim(getFieldValue(field));
var failures = formatFailures[i];
if (typeof(failures[0]) == "object") { // If it's an array
// Go through the expressions and see if any match and see if they all match
var allMatched = true;
var anyMatched = false;
for (var x=0; x < failures.length; x++) {
var exp = new RegExp(failures[x], "gi");
var check = exp.test(value);
if ( !check ) { allMatched = false; }
if ( check ) { anyMatched = true; }
}
// If the developer says they all have to match to cause a failure, then cause a failure
if (formatMatchAllFailures[i] && allMatched) {
alert(formatMessages[i]);
field.focus();
return false; // Return as soon as a failure is detected
}
// If the developer says that any match causes a failure, then cause a failure
if (!formatMatchAllFailures[i] && anyMatched ) {
alert(formatMessages[i]);
field.focus();
return false; // Return as soon as a failure is detected
}
} else { // The formatSuccesses entry is a single value, not an array
var exp = new RegExp(failures, "gi");
var check = exp.test(value);
if ( check ) { // If that single expression matched the criteria (thus, a failure)
alert(formatMessages[i]);
field.focus();
return false; // Return as soon as a failure is detected
}
} // Ends the check to see if the format successes entry is an array or a single value
} // Ends the check to see if the field exists
} // Move on to the next field
return true; // If we made it this far, everything passed
} // Ends the "areFailuresPresent" function
function isFormFormattedCorrectly(form) {
evenOutArrays();
if ( !(areRequiredFieldsPresent(form)) ) { return false; } // Return as soon as a failure is detected
if ( !(areSuccessesPresent(form)) ) { return false; }
if ( !(areFailuresPresent(form)) ) { return false; }
return true;
} // Ends the "isFormFormattedCorrectly" function