google / google/libaddressinput

Improve Spain postcode regex

Open
#245 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
624
Forks
109
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.