Skip to main content

Decorator Reference

All built-in validation decorators live under Source/Pipes/Decorators/. Each is a Delphi RTTI attribute that annotates a DTO property. The TValidationPipe scans the RTTI of the DTO class at runtime and invokes the corresponding constraint.

Usage pattern

uses
Nidus.Decorator.IsEmail,
Nidus.Decorator.IsNotEmpty;

type
TMyDto = class
public
[IsNotEmpty('Field is required')]
property Name: string read FName write FName;

[IsEmail('Must be a valid email')]
property Email: string read FEmail write FEmail;
end;

The msg parameter is the error message returned when validation fails.

Common / string validators

AttributeUnitDescription
[IsNotEmpty(msg)]Nidus.Decorator.IsNotEmptyValue must not be empty or whitespace
[IsEmpty(msg)]Nidus.Decorator.IsEmptyValue must be empty
[IsDefined(msg)]Nidus.Decorator.IsDefinedValue must not be nil / unassigned
[IsEquals(other, msg)]Nidus.Decorator.IsEqualsValue must equal other
[IsIn(vals, msg)]Nidus.Decorator.IsInValue must be in the allowed set
[IsAlpha(msg)]Nidus.Decorator.IsAlphaLetters only
[IsAlphaNumeric(msg)]Nidus.Decorator.IsAlphaNumericLetters and digits only
[IsAscii(msg)]Nidus.Decorator.IsAsciiASCII characters only
[Contains(sub, msg)]Nidus.Decorator.ContainsMust contain substring
[IsFullWidth(msg)]Nidus.Decorator.IsFullWidthFull-width characters
[IsHalfWidth(msg)]Nidus.Decorator.IsHalfWidthHalf-width characters

Numeric validators

AttributeUnitDescription
[IsInteger(msg)]Nidus.Decorator.IsIntegerMust be an integer
[IsNumber(msg)]Nidus.Decorator.IsNumberMust be a number
[IsDivisibleBy(n, msg)]Nidus.Decorator.IsDivisibleByMust be divisible by n
[IsByteLength(min, max, msg)]Nidus.Decorator.IsByteLengthByte length in range

Type validators

AttributeUnitDescription
[IsBoolean(msg)]Nidus.Decorator.IsBooleanMust be a boolean
[IsBooleanString(msg)]Nidus.Decorator.IsBooleanStringMust be "true" / "false"
[IsEnum(TEnum, msg)]Nidus.Decorator.IsEnumMust be a valid enum value
[IsInstance(TClass, msg)]Nidus.Decorator.IsInstanceMust be an instance of TClass
[IsAllow(vals, msg)]Nidus.Decorator.IsAllowMust be in the allowed set

Format validators

AttributeUnitDescription
[IsEmail(msg)]Nidus.Decorator.IsEmailRFC 5322 email
[IsUUID(msg)]Nidus.Decorator.IsUUIDUUID format
[IsIP(msg)]Nidus.Decorator.IsIPIPv4 or IPv6
[IsURL(msg)]Nidus.Decorator.IsURLURL format
[IsISO8601(msg)]Nidus.Decorator.IsISO8601ISO 8601 date-time
[IsDate(msg)]Nidus.Decorator.IsDateDate value
[IsDateString(msg)]Nidus.Decorator.IsDateStringDate string
[IsHexColor(msg)]Nidus.Decorator.IsHexColorHex color (#RRGGBB)
[IsHexadecimal(msg)]Nidus.Decorator.IsHexadecimalHexadecimal string
[IsHsl(msg)]Nidus.Decorator.IsHslHSL color
[IsCurrency(msg)]Nidus.Decorator.IsCurrencyCurrency format
[IsDataURI(msg)]Nidus.Decorator.IsDataURIData URI
[IsGqdn(msg)]Nidus.Decorator.IsGqdnFully qualified domain name

Financial / identity

AttributeUnitDescription
[IsCreditCard(msg)]Nidus.Decorator.IsCreditCardCredit card number (Luhn)
[IsIban(msg)]Nidus.Decorator.IsIbanIBAN
[IsBic(msg)]Nidus.Decorator.IsBicBIC/SWIFT code
[IsISO4217CurrencyCode(msg)]Nidus.Decorator.IsISO4217CurrencyCodeISO 4217 currency
[IsISO31661Alpha2(msg)]Nidus.Decorator.IsISO31661Alpha2ISO 3166-1 alpha-2 country
[IsISO31661Alpha3(msg)]Nidus.Decorator.IsISO31661Alpha3ISO 3166-1 alpha-3 country
[IsIdentityCard(msg)]Nidus.Decorator.IsIdentityCardIdentity card number
[IsIsin(msg)]Nidus.Decorator.IsIsinISIN securities code
[IsIsbn(msg)]Nidus.Decorator.IsIsbnISBN
[IsEAN(msg)]Nidus.Decorator.IsEANEAN barcode
[IsIson(msg)]Nidus.Decorator.IsIsonISON

Encoding / crypto

AttributeUnitDescription
[IsBase64(msg)]Nidus.Decorator.IsBase64Base64
[IsBase32(msg)]Nidus.Decorator.IsBase32Base32
[IsBase58(msg)]Nidus.Decorator.IsBase58Base58
[IsBase(n, msg)]Nidus.Decorator.IsBaseBase-N encoding
[IsHash(alg, msg)]Nidus.Decorator.IsHashHash string
[IsBTCAddress(msg)]Nidus.Decorator.IsBTCAddressBitcoin address
[IsEthereumAddress(msg)]Nidus.Decorator.IsEethereumAddressEthereum address
[IsFirebasePushId(msg)]Nidus.Decorator.IsFirebasePushIdFirebase Push ID

Array validators

AttributeUnitDescription
[IsArray(msg)]Nidus.Decorator.IsArrayMust be an array
[IsArrayNotEmpty(msg)]Nidus.Decorator.IsArrayNotEmptyArray must not be empty
[IsArrayUnique(msg)]Nidus.Decorator.IsArrayUniqueAll elements must be unique
[IsArrayMinSize(n, msg)]Nidus.Decorator.IsArrayMinSizeMinimum element count
[IsArrayMaxSize(n, msg)]Nidus.Decorator.IsArrayMaxSizeMaximum element count
[ArrayContains(val, msg)]Nidus.Decorator.ArrayContainsArray must contain val
[ArrayNotContains(val, msg)]Nidus.Decorator.ArrayNotContainsArray must not contain val

Password strength

AttributeUnitDescription
[IsStrongPassword(msg)]Nidus.Decorator.IsStrongPasswordMust meet strong-password criteria

Strong-password criteria

The validation logic in Nidus.Validation.IsStrongPassword is currently a stub. Until the implementation is complete, the decorator registers the tag but performs no actual check.

Custom constraints

Implement IValidatorConstraint from Nidus.Validation.Interfaces to create your own constraint, then wrap it in a custom RTTI attribute. Extend TValidatorConstraint (from Nidus.Validator.Constraint) to get the interface wired automatically and override only Validate:

type
TMyConstraint = class(TValidatorConstraint)
public
function Validate(const Value: TValue;
const Args: IValidationArguments): TResultValidation; override;
end;

function TMyConstraint.Validate(const Value: TValue;
const Args: IValidationArguments): TResultValidation;
begin
if {your condition on Value} then
Result.Success(True)
else
Result.Failure(IfThen(Args.Message = '', 'Validation failed', Args.Message));
end;

type
MyRuleAttribute = class(IsAttribute)
public
constructor Create(const AMessage: string = ''); override;
function Validation: TValidation; override;
end;

constructor MyRuleAttribute.Create(const AMessage: string);
begin
inherited Create(AMessage);
FTagName := 'MyRule';
end;

function MyRuleAttribute.Validation: TValidation;
begin
Result := TMyConstraint;
end;