Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

E164 phone numbers don't start with +0 #5517

@LajosCseppento

Description

@LajosCseppento

Randomly noticed this:

export const e164: RegExp = /^\+(?:[0-9]){6,14}[0-9]$/;

This allows phone numbers like +000000000 that are invalid.

Maybe /^\+[1-9]\d{6,14}$/ would be better.

I don't think that the reference is explicit on this, but there are no country codes starting with 0.

See also: https://github.com/colinhacks/zod/pull/3476/changes#diff-c54113cf61ec99691748a3890bfbeb00e10efb3f0a76f03a0fd9ec49072e410aR625

Happy to send a PR if you think this could be improved in Zod v4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions