|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PluginSimpleValidate\helper\Validate; |
|
4
|
|
|
|
|
5
|
|
|
use function PluginSimpleValidate\helper\Cleaner\trim_doubled_space; |
|
6
|
|
|
|
|
7
|
|
|
const VAR_LIMIT = 'limit'; |
|
8
|
|
|
|
|
9
|
|
|
const VAR_MATCH = 'match'; |
|
10
|
|
|
|
|
11
|
|
|
const VAR_LOWER_LIMIT = 'lower'; |
|
12
|
|
|
|
|
13
|
|
|
const VAR_UPPER_LIMIT = 'upper'; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
if (! function_exists('is_true')) { |
|
17
|
|
|
function is_true($value) |
|
18
|
|
|
{ |
|
19
|
|
|
return $value === true; |
|
20
|
|
|
} |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
if (! function_exists('is_number')) { |
|
24
|
|
|
function is_number($value) |
|
25
|
|
|
{ |
|
26
|
|
|
return is_numeric($value); |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
if (! function_exists('is_required')) { |
|
31
|
|
|
function is_required($value) |
|
32
|
|
|
{ |
|
33
|
3 |
|
return !empty(trim_doubled_space($value)); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if (! function_exists('is_empty')) { |
|
38
|
|
|
function is_empty($value) |
|
39
|
|
|
{ |
|
40
|
|
|
return empty(trim_doubled_space($value)); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (! function_exists('is_valid_email')) { |
|
45
|
|
|
function is_valid_email($value) |
|
46
|
|
|
{ |
|
47
|
2 |
|
return preg_match('/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $value); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (! function_exists('is_alpha')) { |
|
52
|
|
|
function is_alpha($value) |
|
53
|
|
|
{ |
|
54
|
|
|
return preg_match("/^([a-z])+$/i", $value); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if (! function_exists('is_alpha_numeric')) { |
|
59
|
|
|
function is_alpha_numeric($value) |
|
60
|
|
|
{ |
|
61
|
|
|
return preg_match("/^([a-z0-9])+$/i", $value); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if (! function_exists('is_decimal')) { |
|
66
|
|
|
function is_decimal($value) |
|
67
|
|
|
{ |
|
68
|
|
|
return preg_match('/^[\-+]?[0-9]+\.[0-9]+$/', $value); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
if (! function_exists('is_true')) { |
|
73
|
|
|
function is_integer($value) |
|
74
|
|
|
{ |
|
75
|
|
|
return preg_match('/^[\-+]?[0-9]+$/', $value); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
if (! function_exists('is_natural')) { |
|
80
|
|
|
function is_natural($value) |
|
81
|
|
|
{ |
|
82
|
|
|
return preg_match('/^[0-9]+$/', $value); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
if (! function_exists('is_natural_no_zero')) { |
|
87
|
|
|
function is_natural_no_zero($value) |
|
88
|
|
|
{ |
|
89
|
|
|
return preg_match('/^[1-9]+[0]*$/', $value); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
if (! function_exists('is_equal')) { |
|
94
|
|
|
function is_equal($value, array $args) |
|
95
|
|
|
{ |
|
96
|
1 |
|
return $value === $args[VAR_MATCH]; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
if (! function_exists('less_than')) { |
|
101
|
|
|
function less_than($value, array $args) |
|
102
|
|
|
{ |
|
103
|
1 |
|
return $value < $args[VAR_LIMIT]; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if (! function_exists('greater_than')) { |
|
108
|
|
|
function greater_than($value, array $args) |
|
109
|
|
|
{ |
|
110
|
|
|
return $value > $args[VAR_LIMIT]; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
if (! function_exists('less_or_equal_than')) { |
|
115
|
|
|
function less_or_equal_than($value, array $args) |
|
116
|
|
|
{ |
|
117
|
|
|
return $value <= $args[VAR_LIMIT]; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
if (! function_exists('greater_or_equal_than')) { |
|
122
|
|
|
function greater_or_equal_than($value, array $args) |
|
123
|
|
|
{ |
|
124
|
|
|
return $value >= $args[VAR_LIMIT]; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
if (! function_exists('between')) { |
|
129
|
|
|
function between($value, array $args) |
|
130
|
|
|
{ |
|
131
|
1 |
|
return $value < $args[VAR_UPPER_LIMIT] && $value > $args[VAR_LOWER_LIMIT]; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
if (! function_exists('between_or_equal')) { |
|
136
|
|
|
function between_or_equal($value, array $args) |
|
137
|
|
|
{ |
|
138
|
|
|
return $value <= $args[VAR_UPPER_LIMIT] && $value >= $args[VAR_LOWER_LIMIT]; |
|
139
|
|
|
} |
|
140
|
|
|
} |