Skip to main content

Try it Live

Run Address examples in the interactive playground
View the complete executable example at playground/src/examples/primitives/address/validate.ts.

    Validation Rules

    With 0x prefix:
    • Exactly 42 characters total
    • First 2 characters: 0x
    • Next 40 characters: valid hex (0-9, a-f, A-F)
    Without 0x prefix:
    • Exactly 40 characters total
    • All characters: valid hex (0-9, a-f, A-F)
    Case insensitive:
    • Accepts lowercase, uppercase, or mixed case
    • Does not validate EIP-55 checksum

    Use Cases

    Input Validation

    Validate user input before parsing:

    Form Validation

    Validate addresses in forms:

    API Input Validation

    Validate addresses in API requests:

    Defensive Programming

    Check before processing:

    Common Invalid Inputs

    Validation Without Checksum

    isValid() does NOT validate EIP-55 checksums:

    Performance

    Fast validation: Checks length and character ranges only. No parsing: Does not allocate or parse hex values. Use before parsing: Validate first to avoid exceptions:

    Type Narrowing

    Use as type guard in TypeScript:

    See Also