-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidation.class.php
More file actions
52 lines (43 loc) · 1.72 KB
/
validation.class.php
File metadata and controls
52 lines (43 loc) · 1.72 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
abstract class validation {
public static function minLength ($string, $minLength) {
if (self::isString($string) && self::isNumeric($minLength))
return strlen($string) >= $minLength;
else
throw new UnexpectedValueException("Expected a string and a numeric value. But got " + gettype($string) + " and " + gettype($minLength));
}
public static function maxLength ($string, $maxLength) {
if (self::isString($string) && self::isNumeric($maxLength))
return strlen($string) <= $maxLength;
else
throw new UnexpectedValueException("Expected a string and a numeric value. But got " + gettype($string) + " and " + gettype($maxLength));
}
public static function length ($string, $minLength, $maxLength) {
if (self::isString($string) && self::isNumeric($minLength) && self::isNumeric($maxLength))
return strlen($string) >= $minLength && strlen($string) <= $maxLength;
else
throw new UnexpectedValueException("Expected a string, numeric and numeric value. But got " + gettype($string) + ", " + gettype($minLength) + " and " + gettype($maxLength));
}
public static function maxNum ($value, $max) {
if (self::isNumeric($value))
return $value <= $max;
else
throw new UnexpectedValueException("Expected numeric value. But got " + gettype($value));
}
public static function minNum ($value, $min) {
if (self::isNumeric($value))
return $value >= $min;
else
throw new UnexpectedValueException("Expected numeric value. But got " + gettype($value));
}
public static function email ($string) {
return filter_var($string, FILTER_VALIDATE_EMAIL);
}
public static function isNumeric ($value) {
return is_numeric($value);
}
public static function isString ($string) {
return is_string($string);
}
}
?>