Documentation
    Preparing search index...

    Type Alias Pattern<Value>

    Pattern: tags.TagBase<
        {
            exclusive: ["format", "pattern"];
            kind: "pattern";
            schema: { pattern: Value };
            target: "string";
            validate: `RegExp("${Serialize<Value>}").test($input)`;
            value: Value;
        },
    >

    Regular expression pattern constraint for strings.

    Pattern<Regex> is a type tag that validates string values match the specified regular expression pattern. Apply it to string properties using TypeScript intersection types.

    This constraint is mutually exclusive with Format - you cannot use both on the same property. Use Pattern for custom regex validation, or Format for standard formats (email, uuid, etc.).

    The pattern should be a valid JavaScript regular expression string without the surrounding slashes. The entire string must match (implicit ^ and $ anchors).

    The constraint is enforced at runtime by typia.is(), typia.assert(), and typia.validate(). It generates pattern in JSON Schema output.

    Type Parameters

    • Value extends string

      Regular expression pattern as a string literal

    Jeongho Nam - https://github.com/samchon

    interface Product {
    // SKU format: 3 letters, dash, 4 digits
    sku: string & Pattern<"^[A-Z]{3}-[0-9]{4}$">;
    // Phone number: digits and optional dashes
    phone: string & Pattern<"^[0-9-]+$">;
    }