Typely
GitHub
  • Overview
    • πŸ‘Welcome!
  • Validations
    • πŸ“Common
    • πŸ”’Number
    • βš–οΈComparable
    • ✏️String
  • Customize errors
    • 🌎Localization
    • πŸ”Sensitive data
  • General
    • 🧩Class VS Struct
    • πŸ–ΌοΈSupported frameworks
    • πŸš€Benchmarks
    • ⚠️Limitations
  • Design decisions
    • πŸ”„Conversions
    • ℹ️Use of interfaces
    • πŸ€Έβ€β™‚οΈUnderlying type comparison
    • πŸ’‚Validations
Powered by GitBook
On this page
  • Length Validator
  • Exact Length Validator
  • MinLength Validator
  • MaxLength Validator
  • Regular Expression Validator
Edit on GitHub
  1. Validations

String

Exclusive validations for strings

Length Validator

Ensures that the length of a string is within the specified range.

Example:

builder.OfString().For("Name").Length(1, 50);

Example error: 'Name' must be between 1 and 50 characters but currently has 51.

String format args:

  • Name: Name of the type being validated

  • Value: Current value of the property

  • MinLength: Minimum length

  • MaxLength: Maximum length

  • ActualLength: Actual number of characters

Exact Length Validator

Ensures that the length of a string is exactly the specified length.

Example:

builder.OfString().For("Code").Length(10);

Example error: 'Code' must contain exactly 10 characters but currently has 11.

String format args:

  • Name: Name of the type being validated

  • Value: Current value of the property

  • ExactLength: Number of characters required

  • ActualLength: Actual number of characters

MinLength Validator

Ensures that the length of a string is higher or equal to the specified value.

Example:

builder.OfString().For("Name").MinLength(10);

Example error: 'Name' must be at least 10 characters but currently has 4.

String format args:

  • Name: Name of the type being validated

  • Value: Current value of the property

  • MinLength: Minimum length

  • ActualLength: Actual number of characters

MaxLength Validator

Ensures that the length of a string is less than or equal to the specified value.

Example:

builder.OfString().For("Name").MaxLength(50);

Example error: 'Name' must be 50 characters or less but currently has 51.

String format args:

  • Name: Name of the type being validated

  • Value: Current value of the property

  • MaxLength: Maximum length

  • ActualLength: Actual number of characters

Regular Expression Validator

Ensures that the string meets the specified regular expression.

Example:

builder.OfString().For("Name").Matches(new Regex("[0-9]{1}"));

Example error: 'Name' is not in the correct format. Expected format '[0-9]{1}'.

String format args:

  • Name: Name of the type being validated

  • Value: Current value of the property

  • ComparisonValue: The regular expression specified

PreviousComparableNextLocalization

Last updated 2 years ago

✏️