openmrs-esm-core

O3 Framework / validator

Function: validator()

validator(validationFunction, message): Validator

Defined in: packages/framework/esm-config/src/validators/validator.ts:25

Constructs a custom validator.

Example

{
  foo: {
    _default: 0,
    _validators: [
      validator(val => val >= 0, "Must not be negative.")
    ]
  }
}

Parameters

validationFunction

ValidatorFunction

Takes the configured value as input. Returns true if it is valid, false otherwise.

message

A string message that explains why the value is invalid. Can also be a function that takes the value as input and returns a string.

string (value) => string

Returns

Validator

A validator ready for use in a config schema