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 hasPattern to Validator #40

Open
gemal opened this issue Sep 13, 2021 · 4 comments
Open

add hasPattern to Validator #40

gemal opened this issue Sep 13, 2021 · 4 comments

Comments

@gemal
Copy link
Contributor

gemal commented Sep 13, 2021

being able to check if here is a pattern for a country would it possible to add fx VAT number format check for Norway

so I could first do a check for "hasPattern" and then call the validateVatNumberFormat if hasPattern returned true

Today all numbers from Norway return false due to this check:

        if (! isset($this->patterns[$country])) {
            return false;
        }

@gemal
Copy link
Contributor Author

gemal commented Sep 13, 2021

Let me know if you accept pull requests? Dont want to waste time... :)

@dannyvankooten
Copy link
Member

Perhaps we should throw an Exception if calling the validate method using an unsupported country code prefix?

Currently the library assumes that the validation method is only called after the isCountryCodeInEU( $countryCode ) method on an instance of the Countries class is called. I agree that we should probably design this in a better way... Open to any ideas you might have!

@VincentLanglet
Copy link
Contributor

Perhaps we should throw an Exception if calling the validate method using an unsupported country code prefix?

This would require a new major version since it's a BC break.

Also, every support of new countries could be considered as a BC break like
#57

Maybe we should let the behavior be decided by the user, with

public function validateVatNumberFormat(string $vatNumber, bool $failIfUnknown = true): bool
{
    // ...
    if (! isset($this->patterns[$country])) {
        return !$failIfUnknown;
    }
    // ...
}

Still, exposing a method to know if the Vat country is supported could be useful

Currently the library assumes that the validation method is only called after the isCountryCodeInEU( $countryCode ) method on an instance of the Countries class is called.

If so, there is currently no call in the VatBundle
https://github.com/ibericode/vat-bundle/blob/32ab2529929952b5921e71763390f7453ca03423/src/Validator/Constraints/VatNumberValidator.php#L15-L51

And the methods/constraints are called validVatNumber and not validEUVatNumber which is an issue.

@indykoning
Copy link

Somewhat within the same scope i would love to be able to get the patterns themselves per country in some way.
Usecase being the ability to add quick pre-validation using the html "pattern" attribute before making the call to validate the vat id

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

Successfully merging a pull request may close this issue.

4 participants