PluginProbe
PostNL for WooCommerce / 4.4.1
PostNL for WooCommerce v4.4.1
5.9.12 5.9.11 5.9.10 5.9.9 5.9.8 5.9.7 5.9.6 trunk 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.1.4 3.1.5 3.1.6 3.1.7 4.0.0 4.0.1 4.0.2 4.3.2 4.3.3 4.4.0 4.4.1 All 72 releases
woo-postnl / vendor / myparcelnl / sdk / src / Helper / ValidatePostalCode.php

ValidatePostalCode.php in PostNL for WooCommerce 4.4.1, at vendor/myparcelnl/sdk/src/Helper/ValidatePostalCode.php

41 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace MyParcelNL\Sdk\src\Helper;
4
5 use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment;
6
7 class ValidatePostalCode
8 {
9 const VALIDATE_POSTAL_CODE_REGEX_NL = '/^[1-9]\d{3}\s?[a-z]{2}$/i';
10 const VALIDATE_POSTAL_CODE_REGEX_BE = '/[1-9]\d{3}$/';
11
12 public static function validate(string $postalCode, ?string $destinationCountry): bool
13 {
14 $validatePostalCode = ValidatePostalCode::getPostalCodeRegexByCountry($destinationCountry);
15
16 if ($validatePostalCode) {
17 return (bool) preg_match($validatePostalCode, $postalCode);
18 }
19
20 return true;
21 }
22
23 /**
24 * @param string $local
25 * @param string $destination
26 *
27 * @return string
28 */
29 public static function getPostalCodeRegexByCountry(string $destination): ?string
30 {
31 switch ($destination) {
32 case AbstractConsignment::CC_NL:
33 return self::VALIDATE_POSTAL_CODE_REGEX_NL;
34 case AbstractConsignment::CC_BE:
35 return self::VALIDATE_POSTAL_CODE_REGEX_BE;
36 default:
37 return null;
38 }
39 }
40 }
41