Validating forms frontend have never been so powerful and easy.
Intuitive DOM API
Dynamic form validation
Parsley is now smarter, it automatically detects your forms’ modifications and adapts its validation accordingly. Simply add, remove or edit fields, Parsley validation will follow!
Tons of built-in validators
Parsley is shipped with more than a dozen useful validators. If not enough, use the awesome Parsley extra Ajax validator or tons of other extended validators provided by the community.
Parsley strongly focuses on #UI and #UX. Override almost every Parsley default behavior to fit yourexact needs.
Still shipped almost bug free. Parsley is strongly tested, and aimed to work on every browser since IE7.
Parsley is Open Source, MIT licensed, and developed to help everyone. It will stay that way. Join us on Github!
A validator is a method to determine if a given value (or sometimes sets of values) is acceptable or not, given some requirement parameters.
Parsley comes with many builtin validators and provides tools to specify your own.
Builtin validators list
These validators are shipped in
parsley.js. Have a look at the Parsley Remote plugin and Parsley Extras for more validators.
Of course, Parsley built-in validators are commonly used validators, and you’ll need some more that fit your specific forms and validations. That’s why Parsley lets you easily create your own validators.
The preferred way to register them (after
parsley.js is loaded) looks like:
The following sections go over the details on how to define a custom validator
There are many ways a validator can specify how to validate data:
||Is passed the input’s value as a string.|
||Use this instead of
||Is passed an array of values, in the case of checkboxes.|
Your custom validator must specify at least one of these. If it can validate both single inputs and multiple (i.e. checkboxes), then you can specify validateMultiple and one of the other two.
Validating functions should return either
true if the value is valid, or
false otherwise. It can instead return a promise that will be resolved if the value is valid, or be rejected otherwise.
You can specify what kind of requirement parameter your custom validator is expecting:
||The most generic kind; requirement passed as is, with no checking.|
||For integers only (e.g. used by
||To be used when decimal numbers are acceptable|
||Requirement can be either a full regexp string (e.g.
||Any value other than
You can also specify an array of these kinds. For example, if a validator has
requirementKind: ['integer', 'integer'], then given the requirement string
"[1, 2]" it will receive
2 as second and third arguments (the first one being the value(s) to validate).
For even cases where more complex parameters are needed, you can specify extra parameters; refer to the source and check how the
remote validator uses that.
You can specify error messages, in as many locales as desired, using the
This is equivalent to calling
addMessage for each locale.
You’ll find in the
src/extra/ directory in Parsley .zip or Github projects many more or less useful validators crafted by the community. A doc here is coming.
|Greater than #2.0||
|Validates that the value is greater than another field’s value or some strict minimum number.|
|Greater than or equal to #2.0||
|Validates that the value is greater than or equal to another field’s value or some minimum number.|
|Less than #2.0||
|Validates that the value is less than another field’s value or some strict maximum number.|
|Less than or equal to #2.0||
|Validates that the value is less than or equal to another field’s value or some minimum number.|
|Validates that the value have at least a certain amount of words|
|Validates that the value have a maximum of a certain amount of words|
|Validates that the value is within a certain range of words|
Thanks for reading,