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

Suggestion: make dashes optional #24

Open
dimitar-kunchev opened this issue Jan 8, 2021 · 0 comments
Open

Suggestion: make dashes optional #24

dimitar-kunchev opened this issue Jan 8, 2021 · 0 comments

Comments

@dimitar-kunchev
Copy link

dimitar-kunchev commented Jan 8, 2021

Suggestion for improvement

After extensive testing of the library against a list of addresses (some invalid, some valid) I have found it would be very useful if it would accept post codes without dashes. For example the format for Brazil is #####-### but often people skip the dash, making it an invalid code. Currently I have implemented this with a wrapper class that uses the ignoreSpaces parameter and replaces - with -? in the expression.

protected function getFormatPattern(string $format, bool $ignoreSpacesAndDashes = false): string {
    if ($ignoreSpacesAndDashes) {
        $format = str_replace('-', '-?', $format);
    }
    $pattern = parent::getFormatPattern($format, $ignoreSpacesAndDashes);
    error_log($pattern);
    return $pattern;
}

That being said I think it would be better if that was baked in the library itself.

(Updated code to fix a pattern bug)

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

No branches or pull requests

1 participant