-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidations.php
More file actions
199 lines (161 loc) · 5.6 KB
/
validations.php
File metadata and controls
199 lines (161 loc) · 5.6 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
function alphaNumeric($value) {
$reg= "/^[A-Za-z0-9]+$/";
return preg_match($reg,$value);
}
function alphaNumericSpace($value) {
$reg = "/^[A-Za-z0-9 ]+$/";
return preg_match($reg,$value);
}
function numbers($value) {
$reg = "/^[0-9]+$/";
return preg_match($reg,$value);
}
function numeric($value) {
$reg = "/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/";
return preg_match($reg,$value);
}
function integer($value) {
$reg = "/(^-?\d\d*$)/";
return preg_match($reg,$value);
}
function decimal($value) {
$reg = "/^[0-9]*\.[0-9]+$/";
return preg_match($reg,$value);
}
function alphabetic($value) {
$reg = "/^[A-Za-z]+$/";
return preg_match($reg,$value);
}
function alphabeticSpace($value) {
$reg = "/^[A-Za-z ]+$/";
return preg_match($reg,$value);
}
function alphabeticNumericPunct($value) {
$reg = "/^[A-Za-z0-9 _.,!?\"']+$/";
return( preg_match($reg,$value));
}
function alphabeticSpaceApost($value) {
$reg = "/^[A-Za-z' ]+$/";
return preg_match($reg,$value);
}
function emailCheck($value) {
$reg = "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/";
return preg_match($reg,$value);
}
function ssNum($value) {
$reg = "/^\d{3}\-?\d{2}\-?\d{4}$/";
return preg_match($reg,$value);
}
function dollarAmount($value) {
$reg = "/^((\$\d*)|(\$\d*\.\d{2})|(\d*)|(\d*\.\d{2}))$/";
return preg_match($reg,$value);
}
//Validates that a string a US zip code in 5 digit format or zip+4 format. 99999 or 99999-9999
function zipCode($value) {
$reg = "/(^\d{5}$)|(^\d{5}-\d{4}$)/";
return preg_match($reg,$value);
}
function state($value) {
$reg = "/^(?-i:A[LKSZRAEP]|C[AOT]|D[EC]|F[LM]|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$/";
return preg_match($reg,$value);
}
//(999) 999-9999 or (999)999-9999
function phoneNum($value) {
$reg = "/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/";
return preg_match($reg,$value);
}
function html($value) {
$reg = "/<\/?\w+((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>/gim";
return preg_match($reg,$value);
}
function sqlMetaChars($value) {
$reg = "/((\%3D)|(=))[^\n]*((\%27)|(\')|(\-\-)|(\%3B)|(;))/i";
return preg_match($reg,$value);
}
function sqlInjection($value) {
$reg = "/\w*((\%27)|(\'))((\%6F)|o|(\%4F))((\%72)|r|(\%52))/i";
return preg_match($reg,$value);
}
function sqlInjectionUnion($value) {
$reg = "/((\%27)|(\'))union/i";
return preg_match($reg,$value);
}
function sqlInjectionSelect($value) {
$reg = "/((\%27)|(\'));\s*select/i";
return preg_match($reg,$value);
}
function sqlInjectionInsert($value) {
$reg = "/((\%27)|(\'));\s*insert/i";
return preg_match($reg,$value);
}
function sqlInjectionDelete($value) {
$reg = "/((\%27)|(\'));\s*delete/i";
return preg_match($reg,$value);
}
function sqlInjectionDrop($value) {
$reg = "/((\%27)|(\'));\s*drop/i";
return preg_match($reg,$value);
}
function sqlInjectionUpdate($value) {
$reg = "/((\%27)|(\'));\s*update/i";
return preg_match($reg,$value);
}
function crossSiteScripting($value) {
$reg = "/((\%3C)|<)((\%2F)|\/)*[a-z0-9\%]+((\%3E)|>)/i";
return preg_match($reg,$value);
}
function crossSiteScriptingImg($value) {
$reg = "/((\%3C)|<)((\%69)|i|(\%49))((\%6D)|m|(\%4D))((\%67)|g|(\%47))[^\n]+((\%3E)|>)/i";
return preg_match($reg,$value);
}
function crossSiteScriptingParanoid($value) {
$reg = "/((\%3C)|<)[^\n]+((\%3E)|>)/i";
return preg_match($reg,$value);
}
//date including leap years since 1900 mm and dd could have 1 or 2 digits with 4 digit year and / separator
function dateValidation($value) {
$reg = "/^(((0?[1-9]|1[012])\/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])\/(29|30)|(0?[13578]|1[02])\/31)\/(19|[2-9]\d)\d{2}|0?2\/29\/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$/";
return preg_match($reg,$value);
}
//Date with leap years. Accepts '.' '-' and '/' as separators d.m.yy to dd.mm.yyyy (or d.mm.yy, etc)
//Ex: dd-mm-yyyy d.mm/yy dd/m.yyyy etc etc Accept 00 years also.
function dateAlternate($value) {
$reg = "/^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/";
return preg_match($reg,$value);
}
// mm/dd/yyyy format
function date1($value) {
$reg = "/(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d/";
return preg_match($reg,$value);
}
// mm-dd-yyyy
function date2($value) {
$reg = "/(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](19|20)\d\d/";
return preg_match($reg,$value);
}
function visa($value) {
$reg = "/^4[0-9]{12}(?:[0-9]{3})?$/";
return preg_match($reg,$value);
}
function mc($value) {
$reg = "/^5[1-5][0-9]{14}$/";
return preg_match($reg,$value);
}
function americanExpress($value) {
$reg = "/^3[47][0-9]{13}$/";
return preg_match($reg,$value);
}
function dinersClub($value) {
$reg = "/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/";
return preg_match($reg,$value);
}
function discover($value) {
$reg = "/^6(?:011|5[0-9]{2})[0-9]{12}$/";
return preg_match($reg,$value);
}
function creditCard($value) {
$reg = "/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/";
return preg_match($reg,$value);
}
?>