decoval
Version:
DecoVal is a decorator-driven validation pattern that allows you to add validation rules directly to the properties of TypeScript classes, simplifying data control and increasing code readability and reusability.
14 lines (13 loc) • 501 B
JavaScript
import { ValidationError } from "../dv/error/validation.error";
import { registerValidation } from "../dv/register.validation";
export function ContainsNumber(message) {
return (target, key) => {
registerValidation(target, key, (value) => {
if (typeof value !== "string")
return;
if (!/\d/.test(value)) {
throw new ValidationError(message || `O campo "${key}" deve conter pelo menos um número.`);
}
});
};
}