const data = { email: 'invalid-email', age: 15};const errors = validate(schema, data, { lang: 'en' });console.log(errors);// [// "Email: Must be a valid email address",// "Age: Must be at least 18"// ]
const errors = validate(schema, data, { lang: 'en', customMessages: { required: 'This field is mandatory', string: { email: 'Please enter a valid email address' }, number: { min: (min) => `You must be at least ${min} years old` } }});
The validate function automatically formats field names by capitalizing the first letter in error messages.
If an unexpected error occurs during validation, the function returns a single-element array:
['An unexpected validation error occurred']
The validate function catches all exceptions and returns a generic error message. Check the returned array to determine if validation succeeded (empty array) or failed (non-empty array).