Validation

Singleton class containing validation methods for validating web forms.

Example

// instantiate Validation singleton
var validate = mojo.helper.Validation.getInstance();

// create set of validation rules
sample.rules.GalleryRules = {
"title": [
{rule: validate.isRequired, errorMsg: "field is required"},
{rule: validate.isLength, errorMsg: "field must be less than 255 characters", params: {max: 255}}
]
}

// execute validation, and get errors found
var errors = validate.execute(sample.rules.GalleryRules, mojo.query("form"));
Summary
Singleton class containing validation methods for validating web forms.
Returns whether or not a value exists.
Returns whether or not a value is of a specified data type.
Returns whether or not a value is valid email address syntax.
Returns whether or not a value is a valid email address list.
Check if a specified value is a URL.
Returns wether or not a value length is within a specified range.
Returns wether or not a numeric value is within a specified range.
Returns whether or not a value matches a specified regex expression.
Returns whether or not a value is a valid American zip code.
Returns whether or not a value is a valid Canadian Postal code.
Executes a set of validation rules against one or more web forms, and returns an array of errors found.
Static function--Returns the instance of the mojo.helper.Validation singleton object.

Functions

isRequired

isRequired: function(value)

Returns whether or not a value exists.

Parameters

value{string}

Returns

{boolean}

isType

isType: function(value,
paramsObj)

Returns whether or not a value is of a specified data type.

Parameters

value{string}
paramsObj{object}

Returns

{boolean}

isEmailAddress

isEmailAddress: function(value)

Returns whether or not a value is valid email address syntax.

Parameters

value{string}

Returns

{boolean}

isEmailAddressList

isEmailAddressList: function(value)

Returns whether or not a value is a valid email address list.

Parameters

value{string}

Returns

{boolean}

isUrl

isUrl: function(value)

Check if a specified value is a URL.

Parameters

value{string}

Returns

{boolean}

isLength

isLength: function(value,
paramsObj)

Returns wether or not a value length is within a specified range.

Parameters

value{string}
paramsObj{object}

Returns

{boolean}

isRange

isRange: function(value,
paramsObj)

Returns wether or not a numeric value is within a specified range.

Parameters

value{string}
paramsObj{object}

Returns

{boolean}

isMatch

isMatch: function(value,
paramsObj)

Returns whether or not a value matches a specified regex expression.

Parameters

value{string}
paramsObj{object}

Returns

{boolean}

isZipCode

isZipCode: function(value)

Returns whether or not a value is a valid American zip code.

Parameters

value{string}
notRequired{boolean}

Returns

{boolean}

isPostalCode

isPostalCode: function(value)

Returns whether or not a value is a valid Canadian Postal code.

Parameters

value{string}

Returns

{boolean}

execute

execute: function(rulesObj,
domElmListObj)

Executes a set of validation rules against one or more web forms, and returns an array of errors found.

Parameters

rulesObj{object}
domElmListObj{Array of DOMElements}

Returns

{Array of Error Objects}

Example

//See above for sample implementation usage.

getInstance

mojo.helper.Validation.getInstance = function()

Static function--Returns the instance of the mojo.helper.Validation singleton object.

Returns

{object} mojo.helper.Validation

isRequired: function(value)
Returns whether or not a value exists.
isType: function(value,
paramsObj)
Returns whether or not a value is of a specified data type.
isEmailAddress: function(value)
Returns whether or not a value is valid email address syntax.
isEmailAddressList: function(value)
Returns whether or not a value is a valid email address list.
isUrl: function(value)
Check if a specified value is a URL.
isLength: function(value,
paramsObj)
Returns wether or not a value length is within a specified range.
isRange: function(value,
paramsObj)
Returns wether or not a numeric value is within a specified range.
isMatch: function(value,
paramsObj)
Returns whether or not a value matches a specified regex expression.
isZipCode: function(value)
Returns whether or not a value is a valid American zip code.
isPostalCode: function(value)
Returns whether or not a value is a valid Canadian Postal code.
execute: function(rulesObj,
domElmListObj)
Executes a set of validation rules against one or more web forms, and returns an array of errors found.
mojo.helper.Validation.getInstance = function()
Static function--Returns the instance of the mojo.helper.Validation singleton object.