Skip to content

Suggestion: make dashes optional #24

@dimitar-kunchev

Description

@dimitar-kunchev

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions