2024-11-05 10:07:40 +08:00

22 lines
691 B
TypeScript

import type { ExecuteRule } from '../interface';
import { format } from '../util';
/**
* Rule for validating whitespace.
*
* @param rule The validation rule.
* @param value The value of the field on the source object.
* @param source The source object being validated.
* @param errors An array of errors that this rule may add
* validation errors to.
* @param options The validation options.
* @param options.messages The validation messages.
*/
const whitespace: ExecuteRule = (rule, value, source, errors, options) => {
if (/^\s+$/.test(value) || value === '') {
errors.push(format(options.messages.whitespace, rule.fullField));
}
};
export default whitespace;