Class CommonValidators
Provides pre-built validators for common validation scenarios.
Inherited Members
Namespace: ValidationFramework
Assembly: ValidationFramework.dll
Syntax
public static class CommonValidators
Methods
| Edit this page View SourceAlphanumericValidator(int, int?, string)
Creates a validator for alphanumeric strings (letters and numbers only).
Declaration
public static Validator<string> AlphanumericValidator(int minLength = 1, int? maxLength = null, string fieldName = "Value")
Parameters
| Type | Name | Description |
|---|---|---|
| int | minLength | The minimum required length. |
| int? | maxLength | The maximum allowed length. If null, no maximum is enforced. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
AnyUuidValidator(string)
Creates a validator that checks if a string is a valid UUID (any version).
Declaration
public static Validator<string> AnyUuidValidator(string fieldName = "UUID")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
ApiKeyValidator(int, int, string)
Creates a validator that checks if a string is a valid API key format.
Declaration
public static Validator<string> ApiKeyValidator(int minLength = 16, int maxLength = 128, string fieldName = "API Key")
Parameters
| Type | Name | Description |
|---|---|---|
| int | minLength | Minimum length of the API key. |
| int | maxLength | Maximum length of the API key. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
Base64Validator(string)
Creates a validator that checks if a string is a valid base64 encoded string.
Declaration
public static Validator<string> Base64Validator(string fieldName = "Base64")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
ColorValidator(string)
Creates a validator that checks if a string is a valid color code (hex, RGB, RGBA, HSL, HSLA).
Declaration
public static Validator<string> ColorValidator(string fieldName = "Color")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
ConfirmValidator(string, string)
Creates a validator that checks if a string matches another string (confirmation).
Declaration
public static Validator<string> ConfirmValidator(string otherValue, string fieldName = "Confirmation")
Parameters
| Type | Name | Description |
|---|---|---|
| string | otherValue | The value to match against. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
CoordinatesValidator(string, string)
Creates a validator that checks if a string is a valid coordinate pair (latitude, longitude).
Declaration
public static Validator<string> CoordinatesValidator(string separator = ",", string fieldName = "Coordinates")
Parameters
| Type | Name | Description |
|---|---|---|
| string | separator | The separator between latitude and longitude (default: comma). |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
CountryCodeValidator(bool, string)
Checks the uppercase format of ISO 3166-1 alpha-2 or alpha-3 country codes. This does not check whether a code is assigned in the ISO registry.
Declaration
public static Validator<string> CountryCodeValidator(bool allowAlpha3 = false, string fieldName = "Country")
Parameters
| Type | Name | Description |
|---|---|---|
| bool | allowAlpha3 | Whether to allow 3-letter country codes. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
CreditCardExpiryValidator(string)
Creates a validator that checks if a string is a valid credit card expiration date.
Declaration
public static Validator<string> CreditCardExpiryValidator(string fieldName = "Expiry Date")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
CreditCardValidator(string)
Creates a validator for credit card numbers using the Luhn algorithm. Validates card number format and checksum.
Declaration
public static Validator<string> CreditCardValidator(string fieldName = "CreditCard")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
CurrencyCodeValidator(string)
Checks the three-letter uppercase format used by ISO 4217 currency codes. This does not check whether a code is assigned in the ISO registry.
Declaration
public static Validator<string> CurrencyCodeValidator(string fieldName = "Currency")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
CurrencyValidator(decimal?, decimal?, string)
Creates a validator for currency amounts with range and decimal place constraints. Ensures non-negative values with maximum 2 decimal places.
Declaration
public static Validator<decimal> CurrencyValidator(decimal? minValue = null, decimal? maxValue = null, string fieldName = "Amount")
Parameters
| Type | Name | Description |
|---|---|---|
| decimal? | minValue | The minimum allowed value. If null, only non-negative constraint applies. |
| decimal? | maxValue | The maximum allowed value. If null, no maximum is enforced. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<decimal> | A configured Validator<T> instance. |
CvvValidator(CreditCardType, string)
Creates a validator that checks if a string is a valid credit card CVV/CVC code.
Declaration
public static Validator<string> CvvValidator(CreditCardType cardType = CreditCardType.Any, string fieldName = "CVV")
Parameters
| Type | Name | Description |
|---|---|---|
| CreditCardType | cardType | The type of credit card (determines CVV length). |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
DateValidator(DateTime?, DateTime?, string)
Creates a validator for dates with optional min and max date constraints.
Declaration
public static Validator<DateTime> DateValidator(DateTime? minDate = null, DateTime? maxDate = null, string fieldName = "Date")
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime? | minDate | The minimum allowed date. If null, no minimum is enforced. |
| DateTime? | maxDate | The maximum allowed date. If null, no maximum is enforced. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<DateTime> | A configured Validator<T> instance. |
DomainValidator(bool, bool, string)
Creates a validator that checks if a string is a valid domain name.
Declaration
public static Validator<string> DomainValidator(bool allowSubdomains = true, bool requireTld = true, string fieldName = "Domain")
Parameters
| Type | Name | Description |
|---|---|---|
| bool | allowSubdomains | Whether to allow subdomains. |
| bool | requireTld | Whether to require a top-level domain. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
EmailValidator(string)
Creates a validator that validates email addresses using a basic regex pattern.
Declaration
public static Validator<string> EmailValidator(string fieldName = "Email")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
EmptyValidator(string)
Creates a validator that checks if a string is empty (null, empty, or whitespace).
Declaration
public static Validator<string> EmptyValidator(string fieldName = "Value")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
EnumValidator<T>(IEnumerable<T>, string)
Creates a validator that checks if a value is in a predefined set of allowed values.
Declaration
public static Validator<T> EnumValidator<T>(IEnumerable<T> allowedValues, string fieldName = "Value") where T : notnull
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | allowedValues | The set of allowed values. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<T> | A configured Validator<T> instance. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value to validate. |
EnumValidator<T>(string)
Creates a validator that checks if a value is a valid enum value.
Declaration
public static Validator<T> EnumValidator<T>(string fieldName = "Value") where T : struct, Enum
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<T> | A configured Validator<T> instance. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value to validate (must be an enum). |
FileExtensionValidator(IEnumerable<string>, bool, string)
Creates a validator that checks if a string is a valid file extension.
Declaration
public static Validator<string> FileExtensionValidator(IEnumerable<string> allowedExtensions, bool caseSensitive = false, string fieldName = "File")
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<string> | allowedExtensions | List of allowed extensions (without dot, e.g., "jpg", "png"). |
| bool | caseSensitive | Whether the extension check is case-sensitive. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
FilePathValidator(string)
Creates a validator that checks if a string is a valid file path.
Declaration
public static Validator<string> FilePathValidator(string fieldName = "File Path")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
GuidStringValidator(string)
Creates a validator that checks if a string is a valid GUID.
Declaration
public static Validator<string> GuidStringValidator(string fieldName = "Guid")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
GuidValidator(string)
Creates a validator that checks if a GUID is valid (not empty).
Declaration
public static Validator<Guid> GuidValidator(string fieldName = "Guid")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<Guid> | A configured Validator<T> instance. |
HexColorValidator(string)
Creates a validator for hexadecimal color codes (e.g., #RRGGBB or #RGB).
Declaration
public static Validator<string> HexColorValidator(string fieldName = "Color")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
InternationalPhoneValidator(bool, string)
Creates a validator that checks if a string is a valid phone number with international support.
Declaration
public static Validator<string> InternationalPhoneValidator(bool allowCountryCode = true, string fieldName = "Phone")
Parameters
| Type | Name | Description |
|---|---|---|
| bool | allowCountryCode | Whether to allow country codes (e.g., +1, +44). |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
IpAddressValidator(bool, bool, string)
Creates a validator that checks if a string is a valid IP address (IPv4 or IPv6).
Declaration
public static Validator<string> IpAddressValidator(bool allowIPv4 = true, bool allowIPv6 = true, string fieldName = "IP Address")
Parameters
| Type | Name | Description |
|---|---|---|
| bool | allowIPv4 | Whether to allow IPv4 addresses. |
| bool | allowIPv6 | Whether to allow IPv6 addresses. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
IsbnValidator(string)
Creates a validator that checks if a string is a valid ISBN (10 or 13 digits).
Declaration
public static Validator<string> IsbnValidator(string fieldName = "ISBN")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
JsonValidator(string)
Creates a validator that checks if a string is a valid JSON.
Declaration
public static Validator<string> JsonValidator(string fieldName = "JSON")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
JwtValidator(bool, string)
Creates a validator that checks JWT structure and optionally its expiration claim. This does not authenticate a token or verify its signature, issuer, or audience.
Declaration
public static Validator<string> JwtValidator(bool validateExpiry = false, string fieldName = "JWT")
Parameters
| Type | Name | Description |
|---|---|---|
| bool | validateExpiry | Whether to require a numeric exp claim later than the current UTC time. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
LanguageCodeValidator(string)
Checks a two-letter language code format with an optional two-letter region. This does not check whether the codes are assigned in the ISO registries.
Declaration
public static Validator<string> LanguageCodeValidator(string fieldName = "Language")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
LatitudeValidator(string)
Creates a validator that checks if a string is a valid latitude coordinate.
Declaration
public static Validator<string> LatitudeValidator(string fieldName = "Latitude")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
LengthValidator(int, int?, string)
Creates a validator that checks string length constraints.
Declaration
public static Validator<string> LengthValidator(int minLength = 0, int? maxLength = null, string fieldName = "Value")
Parameters
| Type | Name | Description |
|---|---|---|
| int | minLength | The minimum required length. Values with length less than this will fail validation. |
| int? | maxLength | The maximum allowed length. If null, no maximum is enforced. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
LettersOnlyValidator(bool, bool, bool, string)
Creates a validator that checks if a string contains only letters (including accented characters).
Declaration
public static Validator<string> LettersOnlyValidator(bool allowSpaces = true, bool allowHyphens = true, bool allowApostrophes = true, string fieldName = "Value")
Parameters
| Type | Name | Description |
|---|---|---|
| bool | allowSpaces | Whether to allow spaces between letters. |
| bool | allowHyphens | Whether to allow hyphens between letters. |
| bool | allowApostrophes | Whether to allow apostrophes between letters. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
LongitudeValidator(string)
Creates a validator that checks if a string is a valid longitude coordinate.
Declaration
public static Validator<string> LongitudeValidator(string fieldName = "Longitude")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
MacAddressValidator(string)
Creates a validator that checks if a string is a valid MAC address.
Declaration
public static Validator<string> MacAddressValidator(string fieldName = "MAC Address")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
MimeTypeValidator(string)
Creates a validator that checks if a string is a valid MIME type.
Declaration
public static Validator<string> MimeTypeValidator(string fieldName = "MIME Type")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
NameValidator(int, int, string)
Creates a validator for names with length and character constraints. Allows letters, spaces, hyphens, and apostrophes.
Declaration
public static Validator<string> NameValidator(int minLength = 2, int maxLength = 50, string fieldName = "Name")
Parameters
| Type | Name | Description |
|---|---|---|
| int | minLength | The minimum required length. |
| int | maxLength | The maximum allowed length. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
NotEmptyValidator(string)
Creates a validator that checks if a string is not empty (null, empty, or whitespace).
Declaration
public static Validator<string> NotEmptyValidator(string fieldName = "Value")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
NotNullValidator<T>(string)
Creates a validator that checks if a value is not null.
Declaration
public static Validator<T> NotNullValidator<T>(string fieldName = "Value")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<T> | A configured Validator<T> instance. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value to validate. |
NullValidator<T>(string)
Creates a validator that checks if a value is null.
Declaration
public static Validator<T> NullValidator<T>(string fieldName = "Value")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<T> | A configured Validator<T> instance. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value to validate. |
PasswordValidator(string)
Creates a validator for passwords with strength requirements. Requires at least 8 characters, one uppercase, one lowercase, one digit, and one special character.
Declaration
public static Validator<string> PasswordValidator(string fieldName = "Password")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
PhoneValidator(int, string)
Creates a validator for phone numbers that must contain only digits and have an exact length.
Declaration
public static Validator<string> PhoneValidator(int requiredLength = 10, string fieldName = "Phone")
Parameters
| Type | Name | Description |
|---|---|---|
| int | requiredLength | The exact number of digits required. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
PostalCodeValidator(string, string)
Creates a validator that checks if a string is a valid postal code for various countries.
Declaration
public static Validator<string> PostalCodeValidator(string countryCode, string fieldName = "Postal Code")
Parameters
| Type | Name | Description |
|---|---|---|
| string | countryCode | The ISO 3166-1 alpha-2 country code to validate against. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
RangeValidator<T>(T?, T?, string)
Creates a validator that checks if a value falls within a specified range.
Declaration
public static Validator<T> RangeValidator<T>(T? minValue = null, T? maxValue = null, string fieldName = "Value") where T : struct, IComparable<T>
Parameters
| Type | Name | Description |
|---|---|---|
| T? | minValue | The minimum allowed value. If null, no minimum is enforced. |
| T? | maxValue | The maximum allowed value. If null, no maximum is enforced. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<T> | A configured Validator<T> instance. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value to validate (must be comparable). |
RegexValidator(string, string, string)
Creates a validator that matches strings against a regular expression pattern. Empty or whitespace values are considered valid and skip pattern matching.
Declaration
public static Validator<string> RegexValidator(string pattern, string errorMessage, string fieldName = "Value")
Parameters
| Type | Name | Description |
|---|---|---|
| string | pattern | The regular expression pattern to match. |
| string | errorMessage | The error message to display if validation fails. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
RequiredValidator(string)
Creates a validator that ensures a string value is not null, empty, or whitespace.
Declaration
public static Validator<string> RequiredValidator(string fieldName = "Value")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
SemanticVersionValidator(bool, string)
Creates a validator that checks if a string is a valid semantic version (SemVer).
Declaration
public static Validator<string> SemanticVersionValidator(bool requirePrerelease = false, string fieldName = "Version")
Parameters
| Type | Name | Description |
|---|---|---|
| bool | requirePrerelease | Whether to require prerelease information. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
SlugValidator(int?, bool, string)
Creates a validator that checks if a string is a valid slug (URL-friendly string).
Declaration
public static Validator<string> SlugValidator(int? maxLength = null, bool allowUnderscores = false, string fieldName = "Slug")
Parameters
| Type | Name | Description |
|---|---|---|
| int? | maxLength | Maximum length of the slug. |
| bool | allowUnderscores | Whether to allow underscores. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
SsnValidator(string)
Creates a validator that checks if a string is a valid social security number (SSN) format. Note: This only validates the format, not the actual validity of the number.
Declaration
public static Validator<string> SsnValidator(string fieldName = "SSN")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
StrictUrlValidator(bool, bool, string)
Creates a validator that checks if a string is a valid URL with comprehensive validation.
Declaration
public static Validator<string> StrictUrlValidator(bool requireHttps = false, bool allowLocalhost = false, string fieldName = "URL")
Parameters
| Type | Name | Description |
|---|---|---|
| bool | requireHttps | Whether to require HTTPS protocol. |
| bool | allowLocalhost | Whether to allow localhost URLs. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
StrongPasswordValidator(int, bool, bool, bool, bool, bool, int?, string)
Creates a validator that checks if a string is a valid strong password with customizable requirements.
Declaration
public static Validator<string> StrongPasswordValidator(int minLength = 8, bool requireUppercase = true, bool requireLowercase = true, bool requireNumber = true, bool requireSpecial = true, bool requireNonAlphanumeric = false, int? maxConsecutiveChars = null, string fieldName = "Password")
Parameters
| Type | Name | Description |
|---|---|---|
| int | minLength | Minimum password length. |
| bool | requireUppercase | Whether to require at least one uppercase letter. |
| bool | requireLowercase | Whether to require at least one lowercase letter. |
| bool | requireNumber | Whether to require at least one number. |
| bool | requireSpecial | Whether to require at least one special character. |
| bool | requireNonAlphanumeric | Whether to require at least one non-alphanumeric character. |
| int? | maxConsecutiveChars | Maximum consecutive identical characters allowed. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
TimeValidator(string)
Creates a validator that checks if a string is a valid time in HH:mm or HH:mm:ss format.
Declaration
public static Validator<string> TimeValidator(string fieldName = "Time")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
TimeZoneValidator(string)
Creates a validator that checks if a string is a valid time zone identifier.
Declaration
public static Validator<string> TimeZoneValidator(string fieldName = "Time Zone")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
UrlValidator(string)
Creates a validator for URLs using Uri.TryCreate for validation.
Declaration
public static Validator<string> UrlValidator(string fieldName = "URL")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
UsernameValidator(int, int, string)
Creates a validator for usernames with common constraints. Allows letters, numbers, underscores, and hyphens. Must start with a letter.
Declaration
public static Validator<string> UsernameValidator(int minLength = 3, int maxLength = 20, string fieldName = "Username")
Parameters
| Type | Name | Description |
|---|---|---|
| int | minLength | The minimum required length. |
| int | maxLength | The maximum allowed length. |
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
UuidValidator(string)
Creates a validator that checks if a string is a valid UUID (version 1-5).
Declaration
public static Validator<string> UuidValidator(string fieldName = "UUID")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
WhitespaceValidator(string)
Creates a validator that checks if a string contains only whitespace.
Declaration
public static Validator<string> WhitespaceValidator(string fieldName = "Value")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |
ZipCodeValidator(string)
Creates a validator for US ZIP codes (5-digit or 9-digit format). Supports formats: 12345 or 12345-6789
Declaration
public static Validator<string> ZipCodeValidator(string fieldName = "ZipCode")
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | The name of the field being validated. |
Returns
| Type | Description |
|---|---|
| Validator<string> | A configured Validator<T> instance. |