-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValue.php
More file actions
32 lines (31 loc) · 776 Bytes
/
Value.php
File metadata and controls
32 lines (31 loc) · 776 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
30
31
32
<?php
/**
* Simple Validator class
*/
class Value {
public static function is($validator, $value, $opts = null) {
switch ($validator) {
case 'required':
if (trim($value) == '') return false;
break;
case 'numeric':
return is_numeric($value);
case 'between':
return ($opts[0] <= $value) && ($value <= $opts[1]);
case 'integer':
return is_numeric($value) && ((int)$value == (float)$value);
case 'greater_than':
return $value > $opts[0];
case 'less_than':
return $value < $opts[0];
case 'min_length':
return isset($value[$opts[0]-1]);
case 'max_length':
return !isset($value[$opts[0]]);
case 'between_length':
return isset($value[$opts[0]-1]) && !isset($value[$opts[1]]);
default:
}
return true;
}
}