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

ZipCode validation should be case insensitive #184

Open
stof opened this issue Jul 10, 2024 · 6 comments · May be fixed by #191
Open

ZipCode validation should be case insensitive #184

stof opened this issue Jul 10, 2024 · 6 comments · May be fixed by #191

Comments

@stof
Copy link
Contributor

stof commented Jul 10, 2024

Zipcode patterns are documented as generated from http://i18napis.appspot.com, which does not work anymore. I assume that this is similar to the data available at https://chromium-i18n.appspot.com/ssl-address for the libaddressinput of google.

When looking at the Java library for libaddressinput which consumes this data, the zipcode is matched case insensitively: https://github.com/google/libaddressinput/blob/2610f7b1043d6784ada41392fc9392d1ea09ea07/common/src/main/java/com/google/i18n/addressinput/common/FieldVerifier.java#L156-L163

This library performs case sensitive matching in

return (bool) preg_match('/^('.self::$patterns[$country].')$/', $zipcode);

Would it make sense to update the implementation to match the behavior of libaddressinput ?

@yguedidi
Copy link

@ronanguilloux any news here? would you accept a PR doing the change?

@ronanguilloux
Copy link
Owner

ronanguilloux commented Aug 15, 2024 via email

@ronanguilloux
Copy link
Owner

Hi @stof
It would make sense to update the implementation to have zipcodes matched case-insensitively,
only if you can find evidence that this is nowadays the international-approved standard way to validate zipcodes!

I'm very open to that change, as soon as you find evidence of this from a regulatory body - so not just an example of a validation library implementation.

@yguedidi
Copy link

@ronanguilloux out of curiousity, would you accept if we make it a 3rd optional argument of validate, $caseInsensitive, that will default to false, so at least developers can decide explicitly if they want case sensitive or insensitive validation by usage?
Thanks

@ronanguilloux
Copy link
Owner

Why not? Yes as long as this doesn't start breaking any backward compatibility with the current ZipCode::validate($string, $country) implementation and current default behavior (case-sensitive). Something like ZipCode::validate($string, $country, $case_sensitive=false) should be okay.

yguedidi added a commit to yguedidi/IsoCodes that referenced this issue Feb 24, 2025
| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ronanguilloux#184

Fixes ronanguilloux#184
@yguedidi yguedidi linked a pull request Feb 24, 2025 that will close this issue
@yguedidi
Copy link

@ronanguilloux here the PR: #191

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 a pull request may close this issue.

3 participants