Validation Utility Documentation
ValidationTypes: { Required, Length, Range, Number, Custom, Conditional, List, InverseList, Phone, Same, Email, CustomMulti }


/*
 * The specified field is validated on completion (if it is empty or not).
 * id: the id of this validation (used to identify it in your code) (optional, null if not included)
 * ename: the name of the element this validation checks
 * failureaction: the action to perform on validation failure
 * successaction: the action to perform on validation success
 *
 * Attribute syntax (replace <...> with value for ...) (null if not included, or left out if nothing included after) (only include one per validation (so if it is a set of radio buttons, only put it once)):
 * isrequired="<id>;;;<failureaction>;;;<successaction>"
 *
 * Callback (including failureaction and successaction) parameter array contains (case-sensitive):
 * Type: the type of the validation
 * Id: the id given to this validation
 * Name: the name of the element this validation validates
 * Value: the value of the field
 * Sender: a reference to the validation object calling the callback method
 */

function RequiredValidation(id, ename, failureaction, successaction)


/*
 * The specified field is validated based on string length.
 * id: the id of this validation (used to identify it in your code) (optional, null if not included)
 * ename: the name of the element this validation checks
 * minlen: the minimum length of this field (0 to ignore) (negative numbers become 0)
 * maxlen: the maximum length of this field (0 to ignore) (negative numbers become 0)
 * failureaction: the action to perform on validation failure
 * successaction: the action to perform on validation success
 *
 * Attribute syntax (replace <...> with value for ...) (null if not included, or left out if nothing included after) (only include one per validation (so if it is a set of radio buttons, only put it once)):
 * islength="<id>;;;<minlen>;;;<maxlen>;;;<failureaction>;;;<successaction>"
 *
 * Callback (including failureaction and successaction) parameter array contains (case-sensitive):
 * Type: the type of the validation
 * Id: the id given to this validation
 * Name: the name of the element this validation validates
 * MinLength: the minimum length allowed for the field this validation validates
 * MaxLength: the maximum length allowed for the field this validation validates
 * Value: the value of the field
 * Sender: a reference to the validation object calling the callback method
 */

function LengthValidation(id, ename, minlen, maxlen, failureaction, successaction)


/*
 * The specified field is validated based on if the specified range contains the numerical value of the field. Will fail if field is not numeric.
 * id: the id of this validation (used to identify it in your code) (optional, null if not included)
 * ename: the name of the element this validation checks
 * min: the minimum value of this field (0 to ignore) (negative numbers become 0)
 * max: the maximum value of this field (0 to ignore) (negative numbers become 0)
 * failureaction: the action to perform on validation failure
 * successaction: the action to perform on validation success
 *
 * Attribute syntax (replace <...> with value for ...) (null if not included, or left out if nothing included after) (only include one per validation (so if it is a set of radio buttons, only put it once)):
 * isrange="<id>;;;<min>;;;<max>;;;<failureaction>;;;<successaction>"
 *
 * Callback (including failureaction and successaction) parameter array contains (case-sensitive):
 * Type: the type of the validation
 * Id: the id given to this validation
 * Name: the name of the element this validation validates
 * Min: the minimum value allowed for the field this validation validates
 * Max: the maximum value allowed for the field this validation validates
 * Value: the value of the field
 * Sender: a reference to the validation object calling the callback method
 */

function RangeValidation(id, ename, min, max, failureaction, successaction)


/*
 * The specified field is validated based on if it is numerical or not.
 * id: the id of this validation (used to identify it in your code) (optional, null if not included)
 * ename: the name of the element this validation checks
 * failureaction: the action to perform on validation failure
 * successaction: the action to perform on validation success
 *
 * Attribute syntax (replace <...> with value for ...) (null if not included, or left out if nothing included after) (only include one per validation (so if it is a set of radio buttons, only put it once)):
 * isnumber="<id>;;;<failureaction>;;;<successaction>"
 *
 * Callback (including failureaction and successaction) parameter array contains (case-sensitive):
 * Type: the type of the validation
 * Id: the id given to this validation
 * Name: the name of the element this validation validates
 * Value: the value of the field
 * Sender: a reference to the validation object calling the callback method
 */

function NumberValidation(id, ename, failureaction, successaction)


/*
 * The specified field is validated based on the return value from the callback function.
 * id: the id of this validation (used to identify it in your code) (optional, null if not included)
 * ename: the name of the element this validation checks
 * callback: the function to call for validating the field
 * failureaction: the action to perform on validation failure
 * successaction: the action to perform on validation success
 *
 * Attribute syntax (replace <...> with value for ...) (null if not included, or left out if nothing included after) (only include one per validation (so if it is a set of radio buttons, only put it once)):
 * iscustom="<id>;;;<callback>;;;<failureaction>;;;<successaction>"
 *
 * Callback (including failureaction and successaction) parameter array contains (case-sensitive):
 * Type: the type of the validation
 * Id: the id given to this validation
 * Name: the name of the element this validation validates
 * Value: the value of the field
 * Sender: a reference to the validation object calling the callback method
 */

function CustomValidation(id, ename, callback, failureaction, successaction)


/*
 * The othervalidation object is used to validate, but only if the callback function returns true.
 * id: the id of this validation (used to identify it in your code) (optional, null if not included)
 * callback: the function to call for determining whether or not to validate
 * othervalidation: the validation object to use to validate if the callback function returns true (conditional validation object not allowed)
 * failureaction: the action to perform on validation failure
 * successaction: the action to perform on validation success
 *
 * Attribute syntax (replace <...> with value for ...) (null if not included, or left out if nothing included after) (only include one per validation (so if it is a set of radio buttons, only put it once)):
 * isconditional="<id>;;;<type of othervalidation>;;;<callback>;;;<failureaction>;;;<successaction>;;;<attribute syntax for othervalidation>"
 *
 * Callback (including failureaction and successaction) parameter array contains (case-sensitive):
 * Type: the type of the validation
 * Id: the id given to this validation
 * Other: a reference to the validation object used in the conditional validation
 * Sender: a reference to the validation object calling the callback method
 */

function ConditionalValidation(id, callback, othervalidation, failureaction, successaction)


/*
 * The specified field is validated based on if its value is contained in the list (true) or not (false).
 * id: the id of this validation (used to identify it in your code) (optional, null if not included)
 * ename: the name of the element this validation checks
 * vals: the array of values that are allowed
 * ignorecase: true to ignore case when checking, false to perform case-sensitive check
 * failureaction: the action to perform on validation failure
 * successaction: the action to perform on validation success
 *
 * Attribute syntax (replace <...> with value for ...) (null if not included, or left out if nothing included after) (only include one per validation (so if it is a set of radio buttons, only put it once)):
 * islist="<id>;;;<items of vals, seperated by commas (no spaces)>;;;<ignorecase>;;;<failureaction>;;;<successaction>"
 *
 * Callback (including failureaction and successaction) parameter array contains (case-sensitive):
 * Type: the type of the validation
 * Id: the id given to this validation
 * Name: the name of the element this validation validates
 * Values: the allowed values for the element this validation validates
 * IgnoreCase: the boolean value determining if case is to be ignored when validating
 * Value: the value of the field
 * Sender: a reference to the validation object calling the callback method
 */

function ListValidation(id, ename, vals, ignorecase, failureaction, successaction)


/*
 * The specified field is validated based on if its value is contained in the list (false) or not (true).
 * id: the id of this validation (used to identify it in your code) (optional, null if not included)
 * ename: the name of the element this validation checks
 * vals: the array of values that are not allowed
 * ignorecase: true to ignore case when checking, false to perform case-sensitive check
 * failureaction: the action to perform on validation failure
 * successaction: the action to perform on validation success
 *
 * Attribute syntax (replace <...> with value for ...) (null if not included, or left out if nothing included after) (only include one per validation (so if it is a set of radio buttons, only put it once)):
 * isinverselist="<id>;;;<items of vals, seperated by commas (no spaces)>;;;<ignorecase>;;;<failureaction>;;;<successaction>"
 *
 * Callback (including failureaction and successaction) parameter array contains (case-sensitive):
 * Type: the type of the validation
 * Id: the id given to this validation
 * Name: the name of the element this validation validates
 * Values: the disallowed values for the element this validation validates
 * IgnoreCase: the boolean value determining if case is to be ignored when validating
 * Value: the value of the field
 * Sender: a reference to the validation object calling the callback method
 */

function InverseListValidation(id, ename, vals, ignorecase, failureaction, successaction)


/*
 * The specified field is validated based on if its value is a valid phone number or not.
 * id: the id of this validation (used to identify it in your code) (optional, null if not included)
 * ename: the name of the element this validation checks
 * failureaction: the action to perform on validation failure
 * successaction: the action to perform on validation success
 *
 * Attribute syntax (replace <...> with value for ...) (null if not included, or left out if nothing included after) (only include one per validation (so if it is a set of radio buttons, only put it once)):
 * isphone="<id>;;;<failureaction>;;;<successaction>"
 *
 * Callback (including failureaction and successaction) parameter array contains (case-sensitive):
 * Type: the type of the validation
 * Id: the id given to this validation
 * Name: the name of the element this validation validates
 * Value: the value of the field
 * Sender: a reference to the validation object calling the callback method
 */

function PhoneValidation(id, ename, failureaction, successaction)


/*
 * The specified fields are validated based on if their values are the same
 * id: the id of this validation (used to identify it in your code) (optional, null if not included)
 * ename1: the name of the first element this validation checks
 * ename2: the name of the second element this validation checks
 * ignorecase: true to ignore case when checking, false to perform case-sensitive check
 * failureaction: the action to perform on validation failure
 * successaction: the action to perform on validation success
 *
 * Attribute syntax (replace <...> with value for ...) (null if not included, or left out if nothing included after) (only include one per validation (so if it is a set of radio buttons, only put it once)):
 * issame="<id>;;;<ename2>;;;<ignorecase>;;;<failureaction>;;;<successaction>"
 *
 * Callback (including failureaction and successaction) parameter array contains (case-sensitive):
 * Type: the type of the validation
 * Id: the id given to this validation
 * Name1: the name of the first element this validation validates
 * Name2: the name of the second element this validation validates
 * IgnoreCase: the boolean value determining if case is to be ignored when validating
 * Value1: the value of the first field
 * Value2: the value of the second field
 * Sender: a reference to the validation object calling the callback method
 */

function SameValidation(id, ename1, ename2, ignorecase, failureaction, successaction)


/*
 * The specified field is validated based on if its value is a valid e-mail address or not.
 * id: the id of this validation (used to identify it in your code) (optional, null if not included)
 * ename: the name of the element this validation checks
 * failureaction: the action to perform on validation failure
 * successaction: the action to perform on validation success
 *
 * Attribute syntax (replace <...> with value for ...) (null if not included, or left out if nothing included after) (only include one per validation (so if it is a set of radio buttons, only put it once)):
 * isemail="<id>;;;<failureaction>;;;<successaction>"
 *
 * Callback (including failureaction and successaction) parameter array contains (case-sensitive):
 * Type: the type of the validation
 * Id: the id given to this validation
 * Name: the name of the element this validation validates
 * Value: the value of the field
 * Sender: a reference to the validation object calling the callback method
 */

function EmailValidation(id, ename, failureaction, successaction)


/*
 * The specified fields are validated based on the return value from the callback function.
 * id: the id of this validation (used to identify it in your code) (optional, null if not included)
 * enames: an array containing the names of the elements this validation checks
 * callback: the function to call for validating the fields
 * failureaction: the action to perform on validation failure
 * successaction: the action to perform on validation success
 *
 * Attribute syntax (replace <...> with value for ...) (null if not included, or left out if nothing included after) (only include one per validation (so if it is a set of radio buttons, only put it once)):
 * iscustommulti="<id>;;;<items of enames (not counting the one this attribute is in), seperated by commas (no spaces)>;;;<callback>;;;<failureaction>;;;<successaction>"
 *
 * Callback (including failureaction and successaction) parameter array contains (case-sensitive):
 * Type: the type of the validation
 * Id: the id given to this validation
 * Names: the names of the elements this validation validates
 * Values: the values of the fields
 * Sender: a reference to the validation object calling the callback method
 */

function CustomMultiValidation(id, enames, callback, failureaction, successaction)




Example:


Conditional checkbox
Conditional text field:
Phone number (Custom) (format: (###) ###-####):
Length text field:
Number text field:
Range text field:
Requirement radio buttons:
Yes
No
Unsure
List text field (must be "hi", "bye", "hello", or "goodbye"):
Inverse list text field (must not be "hi", "bye", "hello", or "goodbye"):
Phone text field:
Same text field 1:
Same text field 2:
Email text field:
Custom multi fields (must add up to 100):






Head code:


<script type="text/javascript" src="validate.js"></script>
<script type="text/javascript">
    var validator;
   function setupValidator()
    {
        validator = new ValidationManager();
        validator.interpretForm(document.getElementById("mainform"));
    }
    var condcall = function(params)
    {
        if(document.getElementsByName("condchk")[0].checked)
            return true;
        return false;
    }
    var indsucc = function(params)
    {
        var obj = document.getElementById(params.Id+"s");
        if(!obj || typeof obj == "undefined")
            return;
        obj.style.display = "none";
    }
    var indfail = function(params)
    {
        var obj = document.getElementById(params.Id+"s");
        if(!obj || typeof obj == "undefined")
            return;
        obj.style.display = "block";
    }
    var cuscall = function(params)
    {
        var res = params.Value.match(/\(\d\d\d\) \d\d\d-\d\d\d\d/g);
        if(!res || typeof res == "undefined" || res.length <= 0)
            return false;
        return true;
    }
    var cusmcall = function(params)
    {
        var total = 0;
        for(var i = 0; i < params.Values.length; i++)
        {
            var val = params.Values[i];
            if(val.length <= 0)
                val = "0";
            total += parseInt(val+"");
        }
        if(total != 100)
            return false;
        return true;
    }
</script>


Body code:


<body onload="setupValidator();">
    <form id="mainform" action="ValidateTest.html" method="post" onsubmit="return validator.fullValidate(null, null);">
        <input type="checkbox" name="condchk" /> Conditional checkbox<br />
        Conditional text field: <input type="text" name="condtxt" isconditional="cond;;;required;;;condcall;;;indfail;;;indsucc" /><span id="conds" style="display:none;color:#FF0000;">If the above checkbox is checked, this field is required.</span><br />
        Phone number (Custom) (format: (###) ###-####): <input type="text" name="cusfld" iscustom="cus;;;cuscall;;;indfail;;;indsucc" /><span id="cuss" style="display:none;color:#FF0000;">This field must follow the specified format.</span><br />
        Length text field: <input type="text" name="lentxt" islength="len;;;3;;;5;;;indfail;;;indsucc" /><span id="lens" style="display:none;color:#FF0000;">This field must be between 3 and 5 characters long.</span><br />
        Number text field: <input type="text" name="numtxt" isnumber="num;;;indfail;;;indsucc" /><span id="nums" style="display:none;color:#FF0000;">This field must contain a number or be blank.</span><br />
        Range text field: <input type="text" name="rantxt" isrange="ran;;;5;;;10;;;indfail;;;indsucc" /><span id="rans" style="display:none;color:#FF0000;">This field must contain a number between 5 and 10.</span><br />
        Requirement radio buttons:<span id="reqs" style="display:none;color:#FF0000;">You must select one of the following options.</span><br />
        <input type="radio" name="reqrad" value="yes" isrequired="req;;;indfail;;;indsucc" /> Yes<br />
        <input type="radio" name="reqrad" value="no" /> No<br />
        <input type="radio" name="reqrad" value="unsure" /> Unsure<br />
        List text field (must be "hi", "bye", "hello", or "goodbye"): <input type="text" name="lsttxt" islist="lst;;;hi,bye,hello,goodbye;;;true;;;indfail;;;indsucc" /><span id="lsts" style="display:none;color:#FF0000;">You must enter one of the specified values.</span><br />
        Inverse list text field (must not be "hi", "bye", "hello", or "goodbye"): <input type="text" name="ilsttxt" isinverselist="ilst;;;hi,bye,hello,goodbye;;;true;;;indfail;;;indsucc" /><span id="ilsts" style="display:none;color:#FF0000;">You must not enter one of the specified values.</span><br />
        Phone text field: <input type="text" name="phntxt" isphone="phn;;;indfail;;;indsucc" /><span id="phns" style="display:none;color:#FF0000;">This field must contain a valid phone number.</span><br />
        Same text field 1: <input type="text" name="samtxt1" issame="sam;;;samtxt2;;;true;;;indfail;;;indsucc" /><span id="sams" style="display:none;color:#FF0000;">This field and the one below it must contain the same value (ignoring case).</span><br />
        Same text field 2: <input type="text" name="samtxt2" /><br />
        Email text field: <input type="text" name="emltxt" isemail="eml;;;indfail;;;indsucc" /><span id="emls" style="display:none;color:#FF0000;">This field must contain a valid e-mail address.</span><br />
        Custom multi fields (must add up to 100): <input type="text" name="cusmtxt1" iscustommulti="cusm;;;cusmtxt2,cusmtxt3,cusmtxt4;;;cusmcall;;;indfail;;;indsucc" /><span id="cusms" style="display:none;color:#FF0000;">This field and the ones below it must add up to 100.</span><br />
        <input type="text" name="cusmtxt2" /><br />
        <input type="text" name="cusmtxt3" /><br />
        <input type="text" name="cusmtxt4" /><br />
        <input type="submit" value="Submit" />
    </form>
</body>