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

[Validation] Add a new PostalCode constraint #32356

Open
javiereguiluz opened this issue Jul 4, 2019 · 6 comments

Comments

Projects
None yet
4 participants
@javiereguiluz
Copy link
Member

commented Jul 4, 2019

Description
Today, via Commerceguys Addressing project I found that Google publishes some useful information about countries which is not available in ICU project: https://chromium-i18n.appspot.com/ssl-address

Among the given data, there's a zip value with a regexp validating the ZIP codes of each country. So, I proposing to parse that data to add a ZIpCode constraint.

How to proceed?

First, let's wait until the community and Core Team approves this proposal. Please, don't send a pull request unless this is approved.

If this gets approved, this is how it could be solved:

  • This file tells you which countries have data defined: https://chromium-i18n.appspot.com/ssl-address/data
  • Then you must parse each file with this pattern: https://www.gstatic.com/chrome/autofill/libaddressinput/chromium-i18n/ssl-address/data/<COUNTRY_CODE> and look for the zip option.

How to use it

    /**
     * @Assert\ZipCode(
     *     countries={"ES", "FR", "DE"},
     *     message="This is not a valid ZIP code."
     * )
     */
    protected $zipCode;

@javiereguiluz javiereguiluz added this to the next milestone Jul 4, 2019

@ro0NL

This comment has been minimized.

Copy link
Contributor

commented Jul 4, 2019

Do you suggest to compile this info in Intl?

Im thinking Countries::getZipCodeFormat('NL')

@ro0NL

This comment has been minimized.

Copy link
Contributor

commented Jul 5, 2019

Also see google/libaddressinput#155 / https://github.com/google/libaddressinput/wiki/AddressValidationMetadata

while i like the intend, im not sure about the source of the data nor its reliability :/ or put different; address validation/parsing/standardization is complex and comes with dedicated services to do it. Im not sure SF should get involved in this domain (and implicitly rely on google to do so)

@javiereguiluz

This comment has been minimized.

Copy link
Member Author

commented Jul 5, 2019

@ro0NL quick comments:

  • The information is in the public domain, so it's OK to parse it.
  • About the reliability, I'm pretty sure it's OK for the ZIP code (other parts of addresses are more complex or can change frequently). Also, this being used in Chrome means that billions of addresses are validated each day with this information.

But it's OK to disagree with this proposal. So, let's wait for more opinions.

@ro0NL

This comment has been minimized.

Copy link
Contributor

commented Jul 5, 2019

I was just thinking if one relies on some address (autofill) service already, then validation might be implied (i.e "no api result" = invalid), in this case Symfony should not conflict with the external constraints.

I like the proposal in general, but in above scenario im not sure it's needed.

And then the next question is what would be the better practice (service vs. symfony) :)

@ro0NL

This comment has been minimized.

Copy link
Contributor

commented Jul 5, 2019

So answering my own question.. 😅, with ZipCode + Country you should have a valid combination without any external services involved, while still generating consistent/valid data to feed e.g. autofill services in the future.

👍

@Seb33300

This comment has been minimized.

Copy link
Contributor

commented Jul 7, 2019

A ZIP Code is a postal code used by the United States

So you should call it postal code if it's a feature we can use worldwide.

@javiereguiluz javiereguiluz changed the title [Validation] Add a new ZipCode constraint [Validation] Add a new PostalCode constraint Jul 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.