Interface for string validation methods without any exclusions

interface StringValidationBuilderBase<T, ExcludedMethods> {
    endsWith(suffix, errorMessage?): StringValidationBuilder<T, "endsWith" | ExcludedMethods>;
    matches(pattern, errorMessage?): StringValidationBuilder<T, ExcludedMethods | "matches">;
    maxLength(length, errorMessage?): StringValidationBuilder<T, ExcludedMethods | "maxLength">;
    minLength(length, errorMessage?): StringValidationBuilder<T, ExcludedMethods | "minLength">;
    startsWith(prefix, errorMessage?): StringValidationBuilder<T, "startsWith" | ExcludedMethods>;
}

Type Parameters

  • T

  • ExcludedMethods extends string = never

Methods

  • Validates that a string field ends with the specified suffix

    ⚠️ Only applicable to string fields

    Parameters

    • suffix: string

      The suffix the string must end with

    • Optional errorMessage: string

      Optional custom error message

    Returns StringValidationBuilder<T, "endsWith" | ExcludedMethods>

    Example

    // String field example
    a.string().validate(v => v.endsWith("-suffix", 'String must end with -suffix'))
  • Validates that a string field matches the specified regular expression pattern

    ⚠️ Only applicable to string fields

    Parameters

    • pattern: string

      The regex pattern the string must match

    • Optional errorMessage: string

      Optional custom error message

    Returns StringValidationBuilder<T, ExcludedMethods | "matches">

    Example

    // String field example
    a.string().validate(v => v.matches("^[a-zA-Z0-9]+$", 'String must match the regex pattern'))
  • Validates that a string field does not exceed the specified length

    ⚠️ Only applicable to string fields

    Parameters

    • length: number

      The maximum length allowed

    • Optional errorMessage: string

      Optional custom error message

    Returns StringValidationBuilder<T, ExcludedMethods | "maxLength">

    Example

    // String field example
    a.string().validate(v => v.maxLength(100, 'String must be at most 100 characters'))
  • Validates that a string field has at least the specified length

    ⚠️ Only applicable to string fields

    Parameters

    • length: number

      The minimum length required

    • Optional errorMessage: string

      Optional custom error message

    Returns StringValidationBuilder<T, ExcludedMethods | "minLength">

    Example

    // String field example
    a.string().validate(v => v.minLength(5, 'String must be at least 5 characters'))
  • Validates that a string field starts with the specified prefix

    ⚠️ Only applicable to string fields

    Parameters

    • prefix: string

      The prefix the string must start with

    • Optional errorMessage: string

      Optional custom error message

    Returns StringValidationBuilder<T, "startsWith" | ExcludedMethods>

    Example

    // String field example
    a.string().validate(v => v.startsWith("prefix-", 'String must start with prefix-'))