Version 1.2 glow.forms.tests
API Quick Reference
JavaScript is required to use the quick reference
Collection of built-in tests that can be added to validate a form field.
You do not generally need to call these functions directly, their names are passed to the Form addTests method.
If you want to create your own custom functions, or to see what the parameters these function take, you should refer to the Creating Custom Tests section of the Validating Forms user guide.
Further Info & Examples
Methods
- ajax
A request to the given URL will be made and the response will be passed to the given callback.
Synopsis
glow.forms.tests.ajax();Example
var handleResponseText = function(response) { if (response.text() == "OK") { return glow.forms.PASS; } else { return glow.forms.FAIL; } } myForm .addTests( "username", ["ajax", {arg: handleResponseText, url: "/cgi/checkname.cgi?name={username}"}] );- count
There must be exactly the given number of values submitted with this name.
Synopsis
glow.forms.tests.count();Example
myForm.addTests( "fieldName", ["count", {arg: "2"}] );- custom
The value will be passed to the given function.
Synopsis
glow.forms.tests.custom();Example
myForm .addTests( "username", ["custom", { arg: function(values, opts, callback, formData) { for (var i = 0, len = values.length; i < len; i++) { if (values[i] == "Jake") { callback(glow.forms.FAIL, "The name Jake is not allowed."); return; } } callback(glow.forms.PASS, "Good name."); } }] );- isEmail
The value must be a valid email address.
Synopsis
glow.forms.tests.isEmail();Example
myForm.addTests( "fieldName", ["isEmail"] );- isNumber
The value must be a valid number.
Synopsis
glow.forms.tests.isNumber();Example
myForm.addTests( "fieldName", ["isNumber"] );- max
The numeric value must be no more than the given value.
Synopsis
glow.forms.tests.max();Example
myForm.addTests( "fieldName", ["max", {arg: "100"}] );- maxCount
There must be no more than the given number of values submitted with this name.
Synopsis
glow.forms.tests.maxCount();Example
myForm.addTests( "fieldName", ["maxCount", {arg: "10"}] );- maxLen
The value must be at most the given number of characters long.
Synopsis
glow.forms.tests.maxLen();Example
myForm.addTests( "fieldName", ["maxLen", {arg: "24"}] );- min
The numeric value must be at least the given value.
Synopsis
glow.forms.tests.min();Example
myForm.addTests( "fieldName", ["min", {arg: "1"}] );- minCount
There must be at least the given number of values submitted with this name.
Synopsis
glow.forms.tests.minCount();Example
myForm.addTests( "fieldName", ["minCount", {arg: "1"}] );- minLen
The value must be at least the given number of characters long.
Synopsis
glow.forms.tests.minLen();Example
myForm.addTests( "fieldName", ["minLen", {arg: "3"}] );- range
The numeric value must be between x..y.
Synopsis
glow.forms.tests.range();Example
myForm.addTests( "fieldName", ["range", {arg: "18..118"}] );- regex
The value must match the given regular expression.
Synopsis
glow.forms.tests.regex();Example
myForm.addTests( "fieldName", ["regex", {arg: /^[A-Z0-9]*$/}] );- required
The value must contain at least one non-whitespace character.
Synopsis
glow.forms.tests.required();Example
myForm.addTests( "fieldName", ["required"] );- sameAs
The value must be the same as the value in the given field.
Synopsis
glow.forms.tests.sameAs();Example
myForm.addTests( "email_confirm", ["sameAs", {arg: "email"}] );