-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDEFormatter.php
More file actions
29 lines (22 loc) · 667 Bytes
/
DEFormatter.php
File metadata and controls
29 lines (22 loc) · 667 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
<?php
declare(strict_types=1);
namespace Brick\Postcode\Formatter;
use Brick\Postcode\CountryPostcodeFormatter;
/**
* Validates and formats postcodes in Germany.
*
* Postcodes consist of 5 digits, without separator.
*
* @see https://en.wikipedia.org/wiki/List_of_postal_codes
* @see https://en.wikipedia.org/wiki/Postal_codes_in_Germany
*/
class DEFormatter implements CountryPostcodeFormatter
{
public function format(string $postcode) : ?string
{
if (preg_match('/^((?:0[1-46-9]\d{3})|(?:[1-357-9]\d{4})|(?:4[0-24-9]\d{3})|(?:6[013-9]\d{3}))$/', $postcode) !== 1) {
return null;
}
return $postcode;
}
}