Skip to content

Format Rules ​

Format rules validate common string formats such as email addresses, URLs, identifiers, JSON, IP addresses, and MAC addresses. Use them after presence rules when a missing or empty value should produce a required-style error first.

Email ​

Requires the value to be a valid email address.

csharp
[Email]
csharp
RuleFor(x => x.Email)
    .Email();

HexColor ​

Requires the value to be a hexadecimal color value in three-, four-, six-, or eight-digit form. The leading # is required.

csharp
[HexColor]
csharp
RuleFor(x => x.BrandColor)
    .HexColor();

Uuid ​

Requires the value to be a valid UUID value.

csharp
[Uuid]
csharp
RuleFor(x => x.ExternalId)
    .Uuid();

Ulid ​

Requires the value to be a valid ULID value.

csharp
[Ulid]
csharp
RuleFor(x => x.PublicId)
    .Ulid();

Ip ​

Requires the value to be a valid IPv4 or IPv6 address.

csharp
[Ip]
csharp
RuleFor(x => x.ClientIp)
    .Ip();

Ipv4 ​

Requires the value to be a valid IPv4 address.

csharp
[Ipv4]
csharp
RuleFor(x => x.ClientIp)
    .Ipv4();

Ipv6 ​

Requires the value to be a valid IPv6 address.

csharp
[Ipv6]
csharp
RuleFor(x => x.ClientIp)
    .Ipv6();

MacAddress ​

Requires the value to be a valid MAC address.

csharp
[MacAddress]
csharp
RuleFor(x => x.DeviceAddress)
    .MacAddress();

Json ​

Requires the value to be valid JSON text.

csharp
[Json]
csharp
RuleFor(x => x.Metadata)
    .Json();

Url ​

Requires the value to be an HTTP or HTTPS URL.

csharp
[Url]
csharp
RuleFor(x => x.Website)
    .Url();

Timezone ​

Requires the value to be a valid time zone identifier.

csharp
[Timezone]
csharp
RuleFor(x => x.Timezone)
    .Timezone();

All packages are released under the MIT License.