Validate Plugin
Back to plugins | Download plugin
The Validate plugin adds a method to the API wrapper which provides validation of multiple data types.
The validate()
method accepts 4 arguments, of which only the first is required:
-
type
[string]
(validation type to use) -
mode
[mixed]
(mode of the validation type used) -
minimum
[number]
(minimum boundry) -
maximum
[number]
(maximum boundry)
nano('input').validate('string', null, 5, 12);
This would check that the text in "input" is a string
, and that it is between 5 and 12 characters in length.
Validation Types
By default, the validate()
method checks that the value is not null
, undefined
, 0
, '0'
, ''
or false
. The available validation types are:
- url
- date (mode is a date mask that checks the format of the input)
- time (mode is a date mask that checks the format of the input)
- password (if mode is boolean "true" then the password must also contain symbols)
- number
- string (if mode is a string the input must be the same)
- object (mode is the name of a property that must exist in the object)
- array