Validators

Validators accept or reject extracted token values. If validation fails, the tokenizer continues searching the input for another match — this is how validators act as filters.

String Checks

ValidatorArgumentsDescription
IsNotEmpty()Rejects null, empty, or whitespace-only values
Contains('text')substringValue must contain the specified text
StartsWith('prefix')prefixValue must start with the specified text
EndsWith('suffix')suffixValue must end with the specified text
MinLength(n)min lengthValue must be at least n characters
MaxLength(n)max lengthValue must be at most n characters
IsAlphanumeric()Value must contain only letters and digits
MatchesRegex('pattern')regex patternValue must match the regex (1s timeout)
IsNotEmpty
C#
var template = "Name: {Name:IsNotEmpty()}";
// Rejects null, empty, or whitespace-only values
Contains
C#
var template = "Email: {Email:Contains('@')}";
// Only accepts values containing "@"
StartsWith
C#
var template = "Id: {Id:StartsWith('USR-')}";
// Only accepts values beginning with "USR-"
EndsWith
C#
var template = "File: {File:EndsWith('.csv')}";
// Only accepts values ending with ".csv"
MinLength
C#
var template = "Password: {Pass:MinLength(8)}";
// Rejects values shorter than 8 characters
MaxLength
C#
var template = "Code: {Code:MaxLength(6)}";
// Rejects values longer than 6 characters
IsAlphanumeric
C#
var template = "Token: {Token:IsAlphanumeric()}";
// Rejects values containing spaces, punctuation, or symbols
MatchesRegex
C#
var template = "Code: {Code:MatchesRegex('^[A-Z]{3}[0-9]{3}$')}";
// Accepts codes like "ABC123", rejects "abc" or "12345"

Type Checks

ValidatorArgumentsDescription
IsInteger()Value must be a valid integer
IsNumeric()Value must be parseable as a number
IsDateTime('format',...)format stringsValue must be a valid date in one of the specified formats
IsGuid()Value must be a valid GUID
IsInteger
C#
var template = "Port: {Port:IsInteger()}";
// Rejects non-integer values like "abc" or "3.14"
IsNumeric
C#
var template = "Amount: {Amount:IsNumeric()}";
// Accepts integers and decimals, rejects non-numeric text
IsDateTime
C#
var template = "Date: {Date:IsDateTime('yyyy-MM-dd','dd/MM/yyyy')}";
// Only accepts dates matching at least one of the specified formats
IsGuid
C#
var template = "Id: {Id:IsGuid()}";
// Only accepts well-formed GUIDs

Format Checks

ValidatorArgumentsDescription
IsEmail()Value must be a valid email address
IsUrl()Value must be an absolute, well-formed URL
IsLooseUrl()Relative or absolute URL (tries http:// prefix)
IsLooseAbsoluteUrl()URL-like string (tries http:// prefix)
IsDomainName()Value must be a valid domain name
IsIpAddress()Value must be a valid IPv4 or IPv6 address
IsPhoneNumber()Value must look like a phone number (6+ digits)
IsEmail
C#
var template = "Contact: {Email:IsEmail()}";
// Only accepts valid email addresses
IsUrl
C#
var template = "Link: {Url:IsUrl()}";
// Only accepts absolute, well-formed URLs (must include scheme)
IsLooseUrl
C#
var template = "Link: {Url:IsLooseUrl()}";
// Accepts relative or absolute URLs; tries http:// prefix if no scheme
IsLooseAbsoluteUrl
C#
var template = "Site: {Site:IsLooseAbsoluteUrl()}";
// Accepts URL-like strings; tries http:// prefix if no scheme given
IsDomainName
C#
var template = "Host: {Host:IsDomainName()}";
// Only accepts valid domain names
IsIpAddress
C#
var template = "Ip: {Ip:IsIpAddress()}";
// Accepts valid IPv4 or IPv6 addresses
IsPhoneNumber
C#
var template = "Phone: {Phone:IsPhoneNumber()}";
// Accepts values that look like a phone number (6+ digits)

Range & Comparison

ValidatorArgumentsDescription
IsInRange(min,max)min, maxNumeric value must be within range (inclusive)
IsNot('value')compare valueValue must not equal the specified string
IsInRange
C#
var template = "Age: {Age:IsInRange(0,150)}";
// Only accepts values between 0 and 150
IsNot
C#
var template = "Status: {Status:IsNot('unknown')}";
// Rejects the value "unknown"; accepts anything else

Validation Behavior

When a validator rejects a value, the tokenizer doesn't fail immediately. Instead, it continues searching the input for another match. This makes validators powerful filters:

C#
var template = "Value: {Number*:IsInteger()}";
var input = "Value: abc\nValue: 42\nValue: xyz";
// Skips "abc" (not integer), matches "42", skips "xyz"

Combine validators with transformers in the same chain. Transformers run first, then validators check the transformed value:

C#
var template = "Port: {Port:Trim(),ToInt(),IsInRange(1,65535)}";
// 1. Trim → 2. Convert to int → 3. Validate range