-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathARFormatter.php
More file actions
34 lines (27 loc) · 854 Bytes
/
ARFormatter.php
File metadata and controls
34 lines (27 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
declare(strict_types=1);
namespace Brick\Postcode\Formatter;
use Brick\Postcode\CountryPostcodeFormatter;
use function preg_match;
/**
* Validates and formats postcodes in Argentina.
*
* The postcode is either 4 digits, or 1 letter + 4 digits + 3 letters, with no separators.
*
* @see https://en.wikipedia.org/wiki/List_of_postal_codes
* @see https://en.wikipedia.org/wiki/Postal_codes_in_Argentina
*/
final class ARFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'The postcode is either 4 digits, or 1 letter + 4 digits + 3 letters, with no separators.';
}
public function format(string $postcode): ?string
{
if (preg_match('/^(([0-9]{4})|([A-Z][0-9]{4}[A-Z]{3}))$/', $postcode) !== 1) {
return null;
}
return $postcode;
}
}