1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PaySys\CardPay; |
4
|
|
|
|
5
|
|
|
use Nette\Utils\Validators; |
6
|
|
|
|
7
|
|
|
|
8
|
1 |
|
class Validator |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
public static function isAmount($s) : bool |
12
|
|
|
{ |
13
|
1 |
|
return (is_string($s) && preg_match('/^\d{1,9}(\.\d{1,2})?$/', $s)); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public static function isIp($s) : bool |
17
|
|
|
{ |
18
|
1 |
|
return (filter_var($s, FILTER_VALIDATE_IP) !== FALSE); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public static function isVariableSymbol($s) : bool |
22
|
|
|
{ |
23
|
1 |
|
return (is_string($s) && preg_match('/^\d{1,10}$/', $s)); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public static function isCurrency($s) : bool |
27
|
|
|
{ |
28
|
1 |
|
return (is_string($s) && in_array($s, [ |
29
|
1 |
|
'978', |
30
|
|
|
'203', |
31
|
|
|
'840', |
32
|
|
|
'826', |
33
|
|
|
'348', |
34
|
|
|
'985', |
35
|
|
|
'756', |
36
|
|
|
'208', |
37
|
|
|
])); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public static function isLang($s) : bool |
41
|
|
|
{ |
42
|
1 |
|
return (is_string($s) && in_array($s, [ |
43
|
1 |
|
'sk', |
44
|
|
|
'en', |
45
|
|
|
'de', |
46
|
|
|
'hu', |
47
|
|
|
'cz', |
48
|
|
|
'es', |
49
|
|
|
'fr', |
50
|
|
|
'it', |
51
|
|
|
'pl', |
52
|
|
|
])); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public static function isMid($s) : bool |
56
|
|
|
{ |
57
|
1 |
|
return (is_string($s) && preg_match('/^\d{3,4}$/', $s)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public static function isKey($s) : bool |
61
|
|
|
{ |
62
|
1 |
|
$hex = '[0-9a-f]{2}'; |
63
|
1 |
|
return (is_string($s) && preg_match('/^(.{64}|.{128}|(' . $hex . ':){63}' . $hex . ')$/', $s)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public static function isRurl($s) : bool |
67
|
|
|
{ |
68
|
1 |
|
return (is_string($s) && Validators::isUri($s)); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public static function isName($s) : bool |
72
|
|
|
{ |
73
|
1 |
|
return (is_string($s) && preg_match('/^[a-zA-Z0-9 \.\-_@]{1,64}$/', $s)); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public static function isTimestamp($s) : bool |
77
|
|
|
{ |
78
|
|
|
return ( |
79
|
1 |
|
is_string($s) && |
80
|
1 |
|
preg_match('/^\d{14}$/', $s) && |
81
|
1 |
|
\DateTime::createFromFormat('dmYHis', $s, new \DateTimeZone('UTC')) instanceof \DateTime && |
82
|
1 |
|
$s === \DateTime::createFromFormat('dmYHis', $s, new \DateTimeZone('UTC'))->format('dmYHis') |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|