Options
* — Required option
Option | HTML attribute | Type | Description |
---|---|---|---|
callback * |
data-fv-callback-callback |
Function | The callback method |
message |
data-fv-callback-message |
String | The error message. The dynamic message is supported |
The callback method must follow the format below:
If you want to return a dynamic message, the callback function must return an object
containing the valid
and message
members:
Look at the dynamic message example.
Example
Basic example
In the following form, user is asked to enter a correct answer of simple operation which is generated randomly.
The captcha is also generated after form submission by triggering the err.form.fv event.
Dynamic message example
The form below ask to enter a secure password, which must satisfies all the following conditions:
- Must be more than 8 characters long
- Must contain at least one upper case character
- Must contain at least one lower case character
- Must contain at least one digit
Showing all messages
It's also possible to show all the messages initially. Then whenever the password passes a particular rule, the message associated with the rule will disappear.
Again, we need to trigger events to archive this. This time, the field events (err.field.fv
and
success.field.fv
) are used.
Example
- Asking fields to be unique
- Building a password strength meter with Dropbox's zxcvbn libary
- Contact form
- Preventing user to have same value as the placeholder
- Supporting multiple date formats
- Terms and conditions agreement validation
- Validating international phone numbers
- Validating percentage values
Related validators
The following validators might be useful to you: