function checkValidation(formInput) {
if (typeof(formInput) != "object") {
alert("Validation not supported on this browser.");
return(false);
}
var message;
if (stringEmpty(formInput.value)) {
message = "Error! There is no input value entered.";
alert(message);
} else if (noAtSign( formInput.value )) {
message = "Error! The address \"" + formInput.value + "\" does not contain an '@' character.";
alert(message);
} else if (nothingBeforeAt(formInput.value)) {
message = "Error! The address \"" + formInput.value;
message += "\" must contain at least one character before the '@' character";
alert(message);
} else if (noLeftBracket(formInput.value)) {
message = "Error! The address \"" + formInput.value;
message += "\" contains a right square bracket ']',\nbut no corresponding left square bracket '['.";
alert(message);
} else if (noRightBracket(formInput.value)) {
message = "Error! The address \"" + formInput.value;
message += "\" contains a left square bracket '[',\nbut no corresponding right square bracket ']'.";
alert( message);
} else if (noValidPeriod(formInput.value)) {
message = "Error! The address \"" + formInput.value + "\" must contain a period ('.') character.";
alert(message);
} else if (noValidSuffix(formInput.value)) {
message = "Error! The address \"" + formInput.value;
message += "\" must contain a two, three or four character suffix.";
alert(message);
} else {
message = "Success! The email address \"" + formInput.value + "\" validates OK.";
alert(message);
}
var objType = typeof(formInput.focus);
if (objType == "object" || objType == "function") {
formInput.focus();
}
return (false);
}
function checkValid (formField) {
if ( checkValidation ( formField ) == true ) {
alert ( 'E-Mail Address Validates OK' );
}
return ( false );
}
function stringEmpty (formField) {
// CHECK THAT THE STRING IS NOT EMPTY
if ( formField.length < 1 ) {
return ( true );
} else {
return ( false );
}
}
function noAtSign (formField) {
// CHECK THAT THERE IS AN '@' CHARACTER IN THE STRING
if (formField.indexOf ('@', 0) == -1) {
return ( true )
} else {
return ( false );
}
}
function nothingBeforeAt (formField) {
// CHECK THERE IS AT LEAST ONE CHARACTER BEFORE THE '@' CHARACTER
if ( formField.indexOf ( '@', 0 ) < 1 ) {
return ( true )
} else {
return ( false );
}
}
function noLeftBracket (formField) {
// IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR LEFT BRACKET
if ( formField.indexOf ( '[', 0 ) == -1 && formField.charAt (formField.length - 1) == ']') {
return ( true )
} else {
return ( false );
}
}
function noRightBracket (formField) {
// IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR RIGHT BRACKET
if (formField.indexOf ( '[', 0 ) > -1 && formField.charAt (formField.length - 1) != ']') {
return ( true );
} else {
return ( false );
}
}
function noValidPeriod (formField) {
// IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
if (formField.indexOf ( '@', 0 ) > 1 && formField.charAt (formField.length - 1 ) == ']')
return ( false );
// CHECK THAT THERE IS AT LEAST ONE PERIOD IN THE STRING
if (formField.indexOf ( '.', 0 ) == -1)
return ( true );
return ( false );
}
function noValidSuffix(formField) {
// IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
if (formField.indexOf('@', 0) > 1 && formField.charAt(formField.length - 1) == ']') {
return ( false );
}
// CHECK THAT THERE IS A TWO OR THREE CHARACTER SUFFIX AFTER THE LAST PERIOD
var len = formField.length;
var pos = formField.lastIndexOf ( '.', len - 1 ) + 1;
if ( ( len - pos ) < 2 || ( len - pos ) > 4 ) {
return ( true );
} else {
return ( false );
}
}