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