1 | <?php |
||
5 | class Phone |
||
6 | { |
||
7 | |||
8 | /** |
||
9 | * indicates that the HTML input type is 'tel' |
||
10 | */ |
||
11 | public const INPUT_TYPE = 'tel'; |
||
12 | |||
13 | /** |
||
14 | * indicates that the 'tel' input regex pattern is for a US formatted phone number, examples: |
||
15 | * ########## |
||
16 | * ###-###-#### |
||
17 | * ### ### #### |
||
18 | * (###)-###-#### |
||
19 | * (###) ###-#### |
||
20 | * |
||
21 | * captures the intl code to the first group (+1) and the rest of the number to group 2 |
||
22 | * +1 (###) ###-#### |
||
23 | */ |
||
24 | public const PATTERN_US = '(\+?\d{1,3})?[\ \-]?(\(?\d{3}\)?[\ \-]?\d{3}[\ \-]?\d{4})'; |
||
25 | |||
26 | /** |
||
27 | * indicates that the 'tel' input regex pattern is for a UK formatted phone number, examples: |
||
28 | * (###) #### #### |
||
29 | * (####) ### #### |
||
30 | * (#####) ## #### |
||
31 | * |
||
32 | * captures the intl code to the first group (+44) and the rest of the number to group 2 |
||
33 | * +44 (###) #### #### |
||
34 | */ |
||
35 | public const PATTERN_UK = '(\+?44)?[\ ]?(\(?(?:(?:\d{3,5})|(?:\d{4} \d{2}))\)?[\-\ ]?\d{2,4}[\-\ ]?\d{2,4})'; |
||
36 | |||
37 | /** |
||
38 | * indicates that the 'tel' input regex pattern is for a France formatted phone number, examples: |
||
39 | * 0# ## ## ## ## |
||
40 | * 0### ## ## ## |
||
41 | * |
||
42 | * captures the intl code to the first group (+33) and the rest of the number to group 2 |
||
43 | * +33 # ## ## ## ## |
||
44 | * 0033 # ## ## ## ## |
||
45 | */ |
||
46 | public const PATTERN_FR = '((?:\+|00)33)?[\ \.\-]*((?:(?:\(0\)[\ \.\-]{0,3})?|0)[1-9](?:(?:[\ \.\-]?\d{2}){4}|\d{2}(?:[\ \.\-]?\d{3}){2}))'; |
||
47 | |||
48 | /** |
||
49 | * indicates that the 'tel' input regex pattern is for a German formatted phone number, examples: |
||
50 | * (0##) ####-#### |
||
51 | * (0###) ####-#### |
||
52 | * (0####) ###-#### |
||
53 | * (03####) ##-#### |
||
54 | * |
||
55 | * captures the intl code to the first group (+49) and the rest of the number to group 2 |
||
56 | * +49 (0##) ####-#### |
||
57 | */ |
||
58 | public const PATTERN_DE = '(\+?49)?[\ \.\-]?(\(?(?:[\d \-\)\–\/\(]+){6,}\)?(?:[\ \.\-–\/]?)(?:[\d]+))'; |
||
59 | |||
60 | /** |
||
61 | * @var array |
||
62 | */ |
||
63 | private $regex_patterns; |
||
64 | |||
65 | /** |
||
66 | * @var array |
||
67 | */ |
||
68 | private $valid_type_options; |
||
69 | |||
70 | |||
71 | /** |
||
72 | * Phone constructor. |
||
73 | */ |
||
74 | public function __construct() |
||
92 | |||
93 | |||
94 | /** |
||
95 | * @return array |
||
96 | */ |
||
97 | public function regexPatterns(): array |
||
101 | |||
102 | |||
103 | /** |
||
104 | * @param bool $constants_only |
||
105 | * @return array |
||
106 | */ |
||
107 | public function validTypeOptions(bool $constants_only = false): array |
||
113 | } |
||
114 |