-
Notifications
You must be signed in to change notification settings - Fork 2
/
Validation.php
114 lines (99 loc) · 3.1 KB
/
Validation.php
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
class Validation
{
/* CHECK IF A $STRING IS INT. */
public static function isNumeric($string){
if (!filter_var($string, FILTER_VALIDATE_INT))
return false;
else
return true;
}
/* CHECK IF A $STRING IS FLOAT. */
public static function isFloat($string){
if (!filter_var($string, FILTER_VALIDATE_FLOAT))
return false;
else
return true;
}
/* CHECK IF A $STRING IS BOOLEAN. */
public static function isBoolean($string){
if (!filter_var($string, FILTER_VALIDATE_BOOLEAN))
return false;
else
return true;
}
/* CHECK IF A VALID IP */
public static function isValidIP($string) {
if (!filter_var($string, FILTER_VALIDATE_IP))
return false;
else
return true;
}
/* CHECK IF A VALID URL */
public static function isValidUrl($string) {
if (!filter_var($string, FILTER_VALIDATE_URL))
return false;
else
return true;
}
/* CHECK IF A VALID EMAIL */
public static function isValidEmail($string) {
if (!filter_var($string, FILTER_VALIDATE_EMAIL))
return false;
else
return true;
}
/* CHECK IF A $STRING IS EQUAL TO OTHER */
public static function isEqual($string1, $string2){
if ($string2 != $string1)
return false;
else
return true;
}
/* CHECK IF A $STRING IS VALIDATE NAMES WITHOUT NUMBERS BUT WITH ~, ^. */
public static function isValidName($string){
if (!preg_match('/^[A-ZÀ-Ÿ][A-zÀ-ÿ\'.]+\s([A-zÀ-ÿ\'.]\s?)*[A-ZÀ-Ÿ.][A-zÀ-ÿ\'.]+$/', $string))
return false;
else
return true;
}
/* CHECK IF A $STRING IS CPF OF CPNJ WITH OR WITHOUT PONTUATION */
public static function isValidCPForCNPJ($string){
if (!preg_match('/^([0-9]{3}\.?[0-9]{3}\.?[0-9]{3}\-?[0-9]{2}|[0-9]{2}\.?[0-9]{3}\.?[0-9]{3}\/?[0-9]{4}\-?[0-9]{2})$/', $string))
return false;
else
return true;
}
/* CHECK IF A $STRING IS CPF OF CPNJ WITH OR WITHOUT PONTUATION */
public static function isValidChave($string){
if (!preg_match('/^([0-9]{4}\-[0-9]{4}\-[0-9]{4}\-[0-9]{4})$/', $string))
return false;
else
return true;
}
/* CHECK IF A $STRING IS A DATE 2020-11-03 */
public static function isDateStd($string){
if (!preg_match('/^([0-9]{4}-[0-9]{2}-[0-9]{2})$/', $string))
return false;
else
return true;
}
/* CHECK IF A $STRING IS A DATE 03/06/1989 */
public static function isDate($string){
if (!preg_match('/^([0-9]{2}\/[0-9]{2}\/[0-9]{4})$/', $string))
return false;
else
return true;
}
public static function isCPForCNPJ($string){
$string = preg_replace('/[^0-9]/', '', $valor);
if (strlen($string) == 11)
{
$result->cpf = $valor;
}
elseif (strlen($string) == 14)
{
$result->cnpj = $valor;
}
}
}