Skip to content

Improve Spain postcode regex #245

Description

@aprat84

The two leftmost digits of a Spanish postal code correspond to the province codes. There are only 52 provinces, whose numbers range from 1 to 52.

Therefore, the regular expression could be a bit more precise, by allowing only valid province codes:
^(?:0[1-9]|[1-4]\d|5[0-2])\d{3}$

Source: https://en.wikipedia.org/wiki/Postal_codes_in_Spain

This is also done in Andorra "AD", where the third digit is one of the seven parishes, which is correctly limited by [1-7] in the regex.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions