@vinejs/vine - v4.0.0-next.1
    Preparing search index...

    Class VineString

    VineString represents a string value in the validation schema. It provides comprehensive string validation with built-in rules for common patterns like email, URL, UUID, and more.

    const schema = vine.string()
    .email()
    .minLength(5)
    .maxLength(100)

    const result = await vine.validate({
    schema,
    data: 'user@example.com'
    })

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    "[ITYPE]": string

    Define the input type of the schema for TypeScript inference

    "[OTYPE]": string

    The output value type of the field after validation. The property points to a type only and not the real value.

    "[COTYPE]": string

    Type marker for camelCase output type inference

    dataTypeValidator?: Validation<any>

    The validation to use for validating the schema data type. Using a data type validator guards custom rules to only run when the data type validation passes.

    class StringSchema extends BaseLiteralType {
    dataTypeValidator = stringDataTypeRule
    }
    rules: {
        in: (
            ...options: [
                options: { choices: string[]
                | ((field: FieldContext) => string[]) },
            ],
        ) => Validation<
            { choices: string[]
            | ((field: FieldContext) => string[]) },
        >;
        jwt: (...options: [options?: undefined]) => Validation<undefined>;
        url: (
            ...options: [options?: IsURLOptions],
        ) => Validation<IsURLOptions | undefined>;
        iban: (...options: [options?: undefined]) => Validation<undefined>;
        uuid: (
            ...options: [options?: { version?: (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8)[] }],
        ) => Validation<
            { version?: (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8)[] }
            | undefined,
        >;
        ulid: (...options: [options?: undefined]) => Validation<undefined>;
        trim: (...options: [options?: undefined]) => Validation<undefined>;
        email: (
            ...options: [options?: IsEmailOptions],
        ) => Validation<IsEmailOptions | undefined>;
        alpha: (
            ...options: [options?: AlphaOptions],
        ) => Validation<AlphaOptions | undefined>;
        ascii: (...options: [options?: undefined]) => Validation<undefined>;
        notIn: (
            ...options: [
                options: { list: string[]
                | ((field: FieldContext) => string[]) },
            ],
        ) => Validation<{ list: string[] | ((field: FieldContext) => string[]) }>;
        regex: (...options: [options: RegExp]) => Validation<RegExp>;
        escape: (...options: [options?: undefined]) => Validation<undefined>;
        sameAs: (
            ...options: [options: { otherField: string }],
        ) => Validation<{ otherField: string }>;
        mobile: (
            ...options: [
                options?: | MobileOptions
                | ((field: FieldContext) => MobileOptions | undefined),
            ],
        ) => Validation<
            | MobileOptions
            | ((field: FieldContext) => MobileOptions | undefined)
            | undefined,
        >;
        string: (...options: [options?: undefined]) => Validation<undefined>;
        hexCode: (...options: [options?: undefined]) => Validation<undefined>;
        passport: (
            ...options: [
                options: PassportOptions
                | ((field: FieldContext) => PassportOptions),
            ],
        ) => Validation<
            PassportOptions
            | ((field: FieldContext) => PassportOptions),
        >;
        endsWith: (
            ...options: [options: { substring: string }],
        ) => Validation<{ substring: string }>;
        confirmed: (
            ...options: [
                options?: { confirmationField?: string }
                | { as?: string },
            ],
        ) => Validation<
            { confirmationField?: string }
            | { as?: string }
            | undefined,
        >;
        activeUrl: (...options: [options?: undefined]) => Validation<undefined>;
        minLength: (
            ...options: [options: { min: number }],
        ) => Validation<{ min: number }>;
        notSameAs: (
            ...options: [options: { otherField: string }],
        ) => Validation<{ otherField: string }>;
        maxLength: (
            ...options: [options: { max: number }],
        ) => Validation<{ max: number }>;
        ipAddress: (
            ...options: [options?: { version: 4 | 6 }],
        ) => Validation<{ version: 4 | 6 } | undefined>;
        creditCard: (
            ...options: [
                options?: | CreditCardOptions
                | ((field: FieldContext) => void | CreditCardOptions | undefined),
            ],
        ) => Validation<
            | CreditCardOptions
            | ((field: FieldContext) => void | CreditCardOptions | undefined)
            | undefined,
        >;
        postalCode: (
            ...options: [
                options?: | PostalCodeOptions
                | ((field: FieldContext) => void | PostalCodeOptions | undefined),
            ],
        ) => Validation<
            | PostalCodeOptions
            | ((field: FieldContext) => void | PostalCodeOptions | undefined)
            | undefined,
        >;
        startsWith: (
            ...options: [options: { substring: string }],
        ) => Validation<{ substring: string }>;
        toUpperCase: (
            ...options: [options?: string | string[]],
        ) => Validation<string | string[] | undefined>;
        toLowerCase: (
            ...options: [options?: string | string[]],
        ) => Validation<string | string[] | undefined>;
        toCamelCase: (...options: [options?: undefined]) => Validation<undefined>;
        fixedLength: (
            ...options: [options: { size: number }],
        ) => Validation<{ size: number }>;
        coordinates: (...options: [options?: undefined]) => Validation<undefined>;
        normalizeUrl: (
            ...options: [options?: Options],
        ) => Validation<Options | undefined>;
        alphaNumeric: (
            ...options: [options?: AlphaOptions],
        ) => Validation<AlphaOptions | undefined>;
        normalizeEmail: (
            ...options: [options?: NormalizeEmailOptions],
        ) => Validation<NormalizeEmailOptions | undefined>;
    } = ...

    Static collection of all available validation rules for strings

    "[SUBTYPE]": string = 'string'

    The subtype identifier for the literal schema field

    "[UNIQUE_NAME]": string = 'vine.string'

    Unique name identifier for union type resolution

    Methods

    • Define a method to parse the input value. The method is invoked before any validation and hence you must perform type-checking to know the value you are working it.

      Parameters

      • callback: ParseFn

      Returns this

    • Adds a validation rule to the schema's validation chain. Rules are executed in the order they are added.

      Parameters

      Returns this

      This schema instance for method chaining

      vine.string().use(minLength({ length: 3 }))
      vine.number().use(customRule({ strict: true }))
    • Enable/disable bail mode for this field. In bail mode, field validations stop after the first error.

      Parameters

      • state: boolean

        Whether to enable bail mode

      Returns VineString

      This schema instance for method chaining

      vine.string().bail(false) // Continue validation after first error
      vine.number().bail(true) // Stop after first error (default)
    • Compiles the literal schema type into a compiler node. This method transforms the schema definition into a format that the validation compiler can process.

      Parameters

      • propertyName: string

        Name of the property being compiled

      • refs: RefsStore

        Reference store for the compiler

      • options: ParserOptions

        Parser options including camelCase conversion

      Returns FieldNode & {} & { subtype: string }

      Compiled literal node with subtype information

    • Type checker function to determine if a value is a string. Required for "unionOfTypes" functionality.

      Parameters

      • value: unknown

        The value to check

      Returns value is string

      True if the value is a string

    • Validates the value to be a valid URL.

      Parameters

      • ...args: [options?: IsURLOptions]

        Optional URL validation options

      Returns VineString

      This string schema instance for method chaining

    • Validates the value to be a valid email address.

      Parameters

      • ...args: [options?: IsEmailOptions]

        Optional email validation options

      Returns VineString

      This string schema instance for method chaining

    • Enforce a minimum length on a string field.

      Parameters

      • expectedLength: number

        The minimum required length

      Returns VineString

      This string schema instance for method chaining

    • Enforce a maximum length on a string field.

      Parameters

      • expectedLength: number

        The maximum allowed length

      Returns VineString

      This string schema instance for method chaining

    • Enforce a fixed length on a string field.

      Parameters

      • expectedLength: number

        The exact required length

      Returns VineString

      This string schema instance for method chaining

    • Ensure the field under validation is confirmed by having another field with the same name.

      Parameters

      • Optionaloptions: { confirmationField: string }

      Returns VineString

    • Ensure the field's value under validation is a subset of the pre-defined list.

      Parameters

      • choices: string[] | ((field: FieldContext) => string[])

      Returns VineString

    • Ensure the field's value under validation is not inside the pre-defined list.

      Parameters

      • list: string[] | ((field: FieldContext) => string[])

      Returns VineString

    • Validates the value to be a valid UUID

      Parameters

      • ...args: [options?: { version?: (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8)[] }]

      Returns VineString