You are here

function _postal_code_validation_validate_PT in Postal Code Validation 7

Implements _postal_code_validation_validate_COUNTRYCODE().

File

countries/pt.inc, line 11
Postal code validation functions for Portugal.

Code

function _postal_code_validation_validate_PT($postal_code) {
  $return = array(
    'country' => 'PT',
  );
  if (preg_match('/^([1-9][0-9]{3})-?([0-9]{3})$/', $postal_code, $matches)) {
    $return['postal_code'] = $matches[1] . '-' . $matches[2];
  }
  else {
    $return['error'] = t('Invalid postal code. Postal codes in Portugal are like "9999-999" and never start with zero.');
  }
  return $return;
}