Parsley: Validators Cheat Sheet

Validating function

NameDescription
validateStringIs passed the input’s value as a string.
validateNumberUse this instead of validateString when only numeric values are acceptable. Parsley will parse the input’s value and pass the number, or reject the value if it’s not an acceptable number
validateDateDefine this to create date values. Parsley will parse the input’s value and pass the date, or reject the value if it’s not an acceptable date.
validateMultipleIs passed an array of values, in the case of checkboxes.

Requirement parameters

Value of requirementTypeDescription
'string'The most generic kind; requirement passed as is, with no checking.
'integer'For integers only (e.g. used by minlength)
'number'To be used when decimal numbers are acceptable
'date'To be used for dates.
'regexp'The requirement can be either a full regexp string (e.g. /hel+o/i) or just a simple expression (e.g. hel+o)
'boolean'Any value other than "false" will be considered to true, including the empty string. This is so data-parsley-required and data-parsley-required=true be treated the same way.

Leave a Reply

Your email address will not be published. Required fields are marked *