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

Include postal code example #128

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scripts/generate_address_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ function create_address_format_definition($countryCode, $rawDefinition)
$addressFormat['postal_code_type'] = $rawDefinition['zip_name_type'];
if (isset($rawDefinition['zip'])) {
$addressFormat['postal_code_pattern'] = $rawDefinition['zip'];
if (isset($rawDefinition['zipex'])) {
$postalCodeExamples = explode(',' , $rawDefinition['zipex']);
$addressFormat['postal_code_example'] = $postalCodeExamples[0];
}
}
if (isset($rawDefinition['postprefix'])) {
// Workaround for https://github.com/googlei18n/libaddressinput/issues/72.
Expand Down Expand Up @@ -358,6 +362,10 @@ function create_subdivision_definition($countryCode, $code, $rawDefinition)
// ones specify a full pattern. Therefore, the postal_code_pattern_type
// value is the same for most subdivisions, and omitted to save space.
}
if (isset($rawDefinition['zipex'])) {
$postalCodeExamples = explode(',' , $rawDefinition['zipex']);
$subdivision['postal_code_example'] = $postalCodeExamples[0];
}

return $subdivision;
}
Expand Down
22 changes: 22 additions & 0 deletions src/AddressFormat/AddressFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ class AddressFormat
*/
protected $postalCodePrefix;

/**
* An example postal code which follows the postal code pattern.
*
* @var string
*/
protected $postalCodeExample;

/**
* The subdivision depth.
*
Expand Down Expand Up @@ -372,6 +379,21 @@ public function getPostalCodePrefix()
return $this->postalCodePrefix;
}

/**
* Gets the postal code example.
*
* This is an example postal code used to provide additional context to the
* end-user. It can be displayed as a placeholder, field description or as
* part of the validation.
* (E.g. Zip code 12345 is not valid for Louisana (Example: 70001).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sentence starts with a parenthesis, but doesn't end with one. I suggest just leaving out the first one and starting with just "E.g."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I've addressed this in 7cb62ca

*
* @return string|null A valid postal code example.
*/
public function getPostalCodeExample()
{
return $this->postalCodeExample;
}

/**
* Gets the subdivision depth.
*
Expand Down
Loading