This website is in progress, you can read the docs from old onefrom Here →
ts-validation
Async Validation

Async Validation

The Validator library supports asynchronous validation rules through the onErrorAsync() method, enabling seamless handling of asynchronous validation checks within your validation workflows.

Example of Async Validation

Define async validation rules using the onErrorAsync() method:

v.validator<User>({
  id: 'userValidator',
  items: {
    email: v.string().required().email().onErrorAsync({
      error: async (value) => {
          return await checkEmailInUse(value); // call async function 'checkEmailInUse'
      },
      message: 'The email is already in use!'
    }),
  }
});

To execute async validation rules, use the following methods:

By using async validation rules and these methods (validateAsync, validateInfoAsync, and validateThrowAsync), you can efficiently handle asynchronous validation scenarios in your application, ensuring robust data validation and error handling. Adjust the async validation logic according to your specific application requirements for optimal performance and functionality.

⚠️
using non async validation methods as validate() will ignore the async validation!