Validation Framework
Search Results for

    Show / Hide Table of Contents

    Class CommonValidators

    Provides pre-built validators for common validation scenarios.

    Inheritance
    object
    CommonValidators
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: ValidationFramework
    Assembly: ValidationFramework.dll
    Syntax
    public static class CommonValidators

    Methods

    | Edit this page View Source

    AlphanumericValidator(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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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).

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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).

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX