Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better validation for EirCode IE #1234

Merged

Conversation

NielsvanDijk
Copy link
Contributor

I was implementing the isPostalCode and was looking for Ireland's postal code (eircode). Looking in the documentation of Ireland i found that the letter O is not used to avoid confusion with the digit 0.

An Eircode is a seven character alpha-numeric code made up of two parts. The first part (a Routing Key) consists of three characters and defines a principal post town span of delivery. The second part (a Unique Identifier) is unique to an address and distinguishes one address from another. A typical Eircode might read A65 F4E2. To avoid confusion, we have not used the letter 'O' in Eircodes, however the number '0' (zero) may be included in the Eircode for your address.

Old regex
/^[A-z]\d[\d|w]\s\w{4}$/i
In this code the pipe | is literally a check on the if the | as a char is present, and not the or sign.

New regex
/^(?!.*(?:o))[A-z]\d[\dw]\s\w{4}$/i
In this code we check if there is in the whole string the character O is present if there is the regex don't match.

Documentation
documentation eircode.ie
eircode-routing-keys
regex101

Copy link
Member

@profnandaa profnandaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for your contrib! 🎉

@profnandaa profnandaa merged commit 33b4446 into validatorjs:master Jan 18, 2020
@NielsvanDijk NielsvanDijk deleted the update-ireland-postal-code branch May 25, 2020 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants