You are here

public function PostalCodeValidation::validate in Postal Code 8

Custom function defining regexes corresponding to different countries.

Parameters

string $country_code: Short country code.

string $value: Value to be validated.

Return value

array Array of errors.

Overrides PostalCodeValidationInterface::validate

File

src/PostalCodeValidation.php, line 31

Class

PostalCodeValidation
Provide additional methods for validations of postal code field.

Namespace

Drupal\postal_code

Code

public function validate($country_code, $value) {
  $postal_code_validation_data = $this
    ->getValidationPatterns();
  $regex = $postal_code_validation_data[$country_code][0];
  $error_array[] = preg_match($regex, $value);
  return $error_array;
}