Field names mapped to one rule or an ordered list of rules. Use the built-in rules or your own functions.
A validator whose validate(data) returns typed, parsed data or per-field errors.
const form = createSchemaValidator({ nic: rules.nic(), phone: rules.optional(rules.mobile()) });
const ok = form.validate({ nic: '921234567V', phone: '0771234567' });
ok.isValid; // true
if (ok.isValid) ok.data.nic.dobString; // '1992-05-02'
form.validate({ nic: 'bad' }).errorCodes; // { nic: 'NIC_INVALID_FORMAT' }
form.validate(null).errorCodes; // { $root: 'SCHEMA_INVALID_ROOT' }
Creates a SchemaValidator from a map of field names to rules. The parsed output type is inferred from the rules.
OptionalschemaMap: Partial<Field names mapped to one rule or an ordered list of rules. Use the built-in rules or your own functions.
A validator whose validate(data) returns typed, parsed data or per-field errors.
const form = createSchemaValidator({ nic: rules.nic(), phone: rules.optional(rules.mobile()) });
const ok = form.validate({ nic: '921234567V', phone: '0771234567' });
ok.isValid; // true
if (ok.isValid) ok.data.nic.dobString; // '1992-05-02'
form.validate({ nic: 'bad' }).errorCodes; // { nic: 'NIC_INVALID_FORMAT' }
form.validate(null).errorCodes; // { $root: 'SCHEMA_INVALID_ROOT' }
Creates a SchemaValidator from a map of field names to rules. The parsed output type is inferred from the rules.