Skip to content

Rules And Fluent API

Arc validation for frontend core provides a fluent API that mirrors common FluentValidation patterns.

Use ruleFor() with a chainable API:

class CreateUserCommandValidator extends CommandValidator<ICreateUserCommand> {
constructor() {
super();
this.ruleFor(c => c.email).notEmpty().emailAddress();
this.ruleFor(c => c.age).greaterThanOrEqual(18);
this.ruleFor(c => c.name).minLength(2).maxLength(50);
}
}
  • notEmpty(), notNull()
  • minLength(), maxLength(), length()
  • emailAddress()
  • matches(regex)
  • greaterThan(), greaterThanOrEqual(), lessThan(), lessThanOrEqual()

Use withMessage() to override defaults:

this.ruleFor(c => c.email)
.notEmpty()
.withMessage('Email address is required');
FluentValidationTypeScript
NotEmpty()notEmpty()
NotNull()notNull()
EmailAddress()emailAddress()
MinimumLength(n)minLength(n)
MaximumLength(n)maxLength(n)
Length(min, max)length(min, max)
Matches(regex)matches(regex)
GreaterThan(n)greaterThan(n)
GreaterThanOrEqualTo(n)greaterThanOrEqual(n)
LessThan(n)lessThan(n)
LessThanOrEqualTo(n)lessThanOrEqual(n)

Complex custom predicates such as .Must() are not supported for generated client-side execution.