Skip to content
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
Copy Markdown
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
Copy Markdown
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