Young Living Common Docs
FormsValidatorsValidators

Validators

Description

Writing validators is extremely simple. A validator is just a function that returns falsy if it passes validation, or returns a string with an error if it fails. It can be synchronous or asynchronous which means you can easily write validators that go to the server. Here is an example of a simple validator:

export function required<T>(messageKey?: string) {
  return (value: T) => {
    return !value && (messageKey || 'RequiredError');
  };
}

Provided Validators

The @yl/react-forms library provides some simple common validators to get you started. You can import them from