-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathATFormatter.php
More file actions
39 lines (30 loc) · 931 Bytes
/
ATFormatter.php
File metadata and controls
39 lines (30 loc) · 931 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
35
36
37
38
39
<?php
declare(strict_types=1);
namespace Brick\Postcode\Formatter;
use Brick\Postcode\CountryPostcodeFormatter;
use Brick\Postcode\FormatHelper\StripPrefix;
use function preg_match;
/**
* Validates and formats postcodes in Austria.
*
* Postcodes consist of 4 digits, without separator. The first digit must be 1-9.
*
* @see https://en.wikipedia.org/wiki/List_of_postal_codes
* @see https://en.wikipedia.org/wiki/Postal_codes_in_Austria
*/
final class ATFormatter implements CountryPostcodeFormatter
{
use StripPrefix;
public function hint(): string
{
return 'Postcodes consist of 4 digits, without separator. The first digit must be 1-9.';
}
public function format(string $postcode): ?string
{
$postcode = $this->stripPrefix($postcode, 'A');
if (preg_match('/^[1-9][0-9]{3}$/', $postcode) !== 1) {
return null;
}
return $postcode;
}
}