Custom Validation Rules Starter Plan

Although we offer many validation rules, sometimes you may need to add your own custom rules. If that's your case, then you're in luck! With KwesForms you can add custom validation rules that validate as you type and on blur like our own validation rules.

Implementation

In order to add custom validation rules, your form must have a unique id. Next you must listen for our kwCustomRulesSet event on your form element and call our global setCustomKwRule function. This function takes 4 arguements:

  • Your form's id.
  • The field's name that needs validation.
  • The error message for your custom rule.
  • A function containing the rule's logic. Your function must:
    • Accept a "value" arguement.
    • Return a boolean. "true" would trigger the validation error.

Example

Below is an example of a custom validation rule on the "email" field, that doesn't accept Gmail accounts.

Notice anything wrong in our docs? Let us know.