103 |
- |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/***************************************************************************
|
|
|
4 |
* Copyright (C) 2009-2011 by Geo Varghese(www.seopanel.in) *
|
|
|
5 |
* sendtogeo@gmail.com *
|
|
|
6 |
* *
|
|
|
7 |
* This program is free software; you can redistribute it and/or modify *
|
|
|
8 |
* it under the terms of the GNU General Public License as published by *
|
|
|
9 |
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
10 |
* (at your option) any later version. *
|
|
|
11 |
* *
|
|
|
12 |
* This program is distributed in the hope that it will be useful, *
|
|
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
15 |
* GNU General Public License for more details. *
|
|
|
16 |
* *
|
|
|
17 |
* You should have received a copy of the GNU General Public License *
|
|
|
18 |
* along with this program; if not, write to the *
|
|
|
19 |
* Free Software Foundation, Inc., *
|
|
|
20 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
21 |
***************************************************************************/
|
|
|
22 |
|
|
|
23 |
# class defines all validations functions
|
|
|
24 |
class Validation{
|
|
|
25 |
|
|
|
26 |
var $flagErr;
|
|
|
27 |
|
|
|
28 |
function __construct(){
|
|
|
29 |
$this->Filters['email'] = "/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i" ;
|
|
|
30 |
$this->Filters['number'] = "/^[0-9]+$/";
|
|
|
31 |
$this->Filters['floatnumber'] = "/^\d+$|^\d+\.\d+$|^\.\d+$|^\-\d+$/";
|
|
|
32 |
$this->Filters['phone'] = "/^[0-9\-\(\)\s\+]+$/";
|
|
|
33 |
$this->Filters['startPhone'] = "/^[0-9\+\(]$/";
|
|
|
34 |
$this->Filters['alpha']= "/^[a-zA-Z]+$/";
|
|
|
35 |
$this->Filters['name']= "/^[a-zA-Z\'\-\s]+$/";
|
|
|
36 |
$this->Filters['startName'] = "/^[a-zA-Z]$/";
|
|
|
37 |
$this->Filters['nameGen'] = "/^[0-9a-zA-Z\-\s\'\!\@\#\$\%\^\&\*\(\)\-\_\+\?\.\:\;\[\]\/\,\"\=]+$/";
|
|
|
38 |
$this->Filters['startGenName'] = $this->Filters['nameGen'];
|
|
|
39 |
$this->Filters['uname'] = "/^[0-9a-zA-Z\-\_\.]+$/";
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
function getUniqueChars($entry){
|
|
|
43 |
$arrVar = preg_split("//", $entry);
|
|
|
44 |
return array_unique($arrVar);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
function checkBlank($entry){
|
|
|
48 |
if(strlen($entry) == 0){
|
|
|
49 |
$msg = $_SESSION['text']['common']['Entry cannot be blank'];
|
|
|
50 |
$this->flagErr = true;
|
|
|
51 |
}
|
|
|
52 |
return $msg;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
function checkAlpha($entry){
|
|
|
56 |
$entry = stripslashes(trim($entry));
|
|
|
57 |
if (!preg_match($this->Filters['alpha'], $entry)){
|
|
|
58 |
$msg = $_SESSION['text']['common']['Invalid characters'];
|
|
|
59 |
$this->flagErr = true;
|
|
|
60 |
}
|
|
|
61 |
return $msg;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
function checkUname($user_name){
|
|
|
65 |
$user_name = stripslashes(trim($user_name));
|
|
|
66 |
if(count($this->getUniqueChars($user_name)) <= 2){
|
|
|
67 |
$msg = $_SESSION['text']['common']['entrynotvalid'];
|
|
|
68 |
$this->flagErr = true;
|
|
|
69 |
}
|
|
|
70 |
if(!preg_match($this->Filters['uname'],$user_name)){
|
|
|
71 |
$msg = $_SESSION['text']['common']['Invalid characters'];
|
|
|
72 |
$this->flagErr = true;
|
|
|
73 |
}
|
|
|
74 |
if(strlen($user_name) == 0){
|
|
|
75 |
$msg = $_SESSION['text']['common']['Entry cannot be blank'];
|
|
|
76 |
$this->flagErr = true;
|
|
|
77 |
}
|
|
|
78 |
return $msg;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
function checkName($entry){
|
|
|
82 |
$entry = stripslashes(trim($entry));
|
|
|
83 |
if(!preg_match($this->Filters['name'],$entry)){
|
|
|
84 |
$msg = $_SESSION['text']['common']['Invalid characters'];
|
|
|
85 |
$this->flagErr = true;
|
|
|
86 |
}
|
|
|
87 |
if(!preg_match($this->Filters['startName'],$entry{0})){
|
|
|
88 |
$msg = $_SESSION['text']['common']['Invalid value'];
|
|
|
89 |
$this->flagErr = true;
|
|
|
90 |
}
|
|
|
91 |
if(strlen($entry) == 0){
|
|
|
92 |
$msg = $_SESSION['text']['common']['Entry cannot be blank'];
|
|
|
93 |
$this->flagErr = true;
|
|
|
94 |
}
|
|
|
95 |
return $msg;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
function checkLastName($entry){
|
|
|
99 |
$entry = stripslashes(trim($entry));
|
|
|
100 |
if(!preg_match($this->Filters['name'],$entry)){
|
|
|
101 |
$msg = $_SESSION['text']['common']['Invalid characters'];
|
|
|
102 |
$this->flagErr = true;
|
|
|
103 |
}
|
|
|
104 |
if(!preg_match($this->Filters['startName'],$entry{0})){
|
|
|
105 |
exit;
|
|
|
106 |
$msg = $_SESSION['text']['common']['Invalid value'];
|
|
|
107 |
$this->flagErr = true;
|
|
|
108 |
}
|
|
|
109 |
if(strlen($entry) == 0){
|
|
|
110 |
$msg = $_SESSION['text']['common']['Entry cannot be blank'];
|
|
|
111 |
$this->flagErr = true;
|
|
|
112 |
}
|
|
|
113 |
return $msg;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
function checkEmail($entry){
|
|
|
117 |
|
|
|
118 |
// check email using php function
|
|
|
119 |
$entry = stripslashes(trim($entry));
|
|
|
120 |
if (filter_var($entry, FILTER_VALIDATE_EMAIL) === false) {
|
|
|
121 |
$msg = $_SESSION['text']['common']["Invalid email address entered"];
|
|
|
122 |
$this->flagErr = true;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
return $msg;
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
function checkPasswords($pass1, $pass2){
|
|
|
129 |
if(strlen($pass1) < 6 || strlen($pass1) > 32){
|
|
|
130 |
$msg = $_SESSION['text']['common']['password632'];
|
|
|
131 |
$this->flagErr = true;
|
|
|
132 |
}
|
|
|
133 |
if($pass1!= $pass2){
|
|
|
134 |
$msg = $_SESSION['text']['common']['passwordnotmatch'];
|
|
|
135 |
$this->flagErr = true;
|
|
|
136 |
}
|
|
|
137 |
return $msg;
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
function checkGenName($entry){
|
|
|
141 |
$entry = stripslashes(trim($entry));
|
|
|
142 |
if(count($this->getUniqueChars($entry)) <= 2){
|
|
|
143 |
$msg = "The value doesnt seem to be valid";
|
|
|
144 |
$this->flagErr = true;
|
|
|
145 |
}
|
|
|
146 |
if(!preg_match($this->Filters['nameGen'],$entry)){
|
|
|
147 |
$msg = $_SESSION['text']['common']['Invalid characters'];
|
|
|
148 |
$this->flagErr = true;
|
|
|
149 |
}
|
|
|
150 |
if(!preg_match($this->Filters['startGenName'],$entry{0})){
|
|
|
151 |
$msg = $_SESSION['text']['common']['Invalid value'];
|
|
|
152 |
$this->flagErr = true;
|
|
|
153 |
}
|
|
|
154 |
if(strlen($entry) == 0){
|
|
|
155 |
$msg = $_SESSION['text']['common']['Entry cannot be blank'];
|
|
|
156 |
$this->flagErr = true;
|
|
|
157 |
}
|
|
|
158 |
if(strval(floatval($entry)) == $entry){
|
|
|
159 |
$msg = "The entry cant be a number.";
|
|
|
160 |
$this->flagErr = true;
|
|
|
161 |
}
|
|
|
162 |
if(!preg_match($this->Filters['alpha'],$entry)){
|
|
|
163 |
$msg = $_SESSION['text']['common']['Invalid characters'];
|
|
|
164 |
$this->flagErr = true;
|
|
|
165 |
}
|
|
|
166 |
return $msg;
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
function checkPhone($entry){
|
|
|
170 |
if(count($this->getUniqueChars($entry)) <= 2){
|
|
|
171 |
$msg = "The entry doesnt seem to be valid";
|
|
|
172 |
$this->flagErr = true;
|
|
|
173 |
}
|
|
|
174 |
if(!preg_match($this->Filters['phone'],$entry)){
|
|
|
175 |
$msg = $_SESSION['text']['common']['Invalid characters'];
|
|
|
176 |
$this->flagErr = true;
|
|
|
177 |
}
|
|
|
178 |
if(!preg_match($this->Filters['startPhone'],$entry{0})){
|
|
|
179 |
$msg = $_SESSION['text']['common']['Invalid value'];
|
|
|
180 |
$this->flagErr = true;
|
|
|
181 |
}
|
|
|
182 |
if(strlen($entry) == 0){
|
|
|
183 |
$msg = $_SESSION['text']['common']['Entry cannot be blank'];
|
|
|
184 |
$this->flagErr = true;
|
|
|
185 |
}
|
|
|
186 |
return $msg;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
function checkZip($entry){
|
|
|
190 |
$entry = stripslashes(trim($entry));
|
|
|
191 |
if(!preg_match($this->Filters['number'],$entry)){
|
|
|
192 |
$msg = $_SESSION['text']['common']['Invalid characters'];
|
|
|
193 |
$this->flagErr = true;
|
|
|
194 |
}
|
|
|
195 |
if(strlen($entry) == 0){
|
|
|
196 |
$msg = $_SESSION['text']['common']['Entry cannot be blank'];
|
|
|
197 |
$this->flagErr = true;
|
|
|
198 |
}
|
|
|
199 |
return $msg;
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
function checkNumber($entry){
|
|
|
203 |
$entry = stripslashes(trim($entry));
|
|
|
204 |
if(!preg_match($this->Filters['floatnumber'],$entry)){
|
|
|
205 |
$msg = $_SESSION['text']['common']['Invalid characters'];
|
|
|
206 |
$this->flagErr = true;
|
|
|
207 |
}
|
|
|
208 |
if(strlen($entry) == 0){
|
|
|
209 |
$msg = $_SESSION['text']['common']['Entry cannot be blank'];
|
|
|
210 |
$this->flagErr = true;
|
|
|
211 |
}
|
|
|
212 |
return $msg;
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
function checkUnameLength($name){
|
|
|
216 |
if(strlen($name) < 6){
|
|
|
217 |
$msg = "The username string should have a length atleast of 6";
|
|
|
218 |
$this->flagErr = true;
|
|
|
219 |
}elseif(!preg_match('/\d+/',$name)){
|
|
|
220 |
$msg = "The username string should have a atleast a number";
|
|
|
221 |
$this->flagErr = true;
|
|
|
222 |
}elseif(!preg_match('/[a-zA-Z]+/',$name)){
|
|
|
223 |
$msg = "The username string should have a atleast a letter";
|
|
|
224 |
$this->flagErr = true;
|
|
|
225 |
}
|
|
|
226 |
return $msg;
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
# func to check captcha
|
|
|
230 |
function checkCaptcha($code) {
|
|
|
231 |
$msg = '';
|
|
|
232 |
if(!PhpCaptcha::Validate($_POST['code'])){
|
|
|
233 |
$msg = $_SESSION['text']['common']["Invalid code entered"];
|
|
|
234 |
$this->flagErr = true;
|
|
|
235 |
}
|
|
|
236 |
return $msg;
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
# func to check date
|
|
|
240 |
function checkDate($date, $delimiter = '-') {
|
|
|
241 |
$msg = '';
|
|
|
242 |
$dateElements = explode($delimiter, $date);
|
|
|
243 |
|
|
|
244 |
// explode and check the number of elements
|
|
|
245 |
if (count($dateElements) == 3) {
|
|
|
246 |
if (checkdate($dateElements[1], $dateElements[2], $dateElements[0])) {
|
|
|
247 |
return $msg;
|
|
|
248 |
}
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
$msg = $_SESSION['text']['common']['Invalid characters'];
|
|
|
252 |
$this->flagErr = true;
|
|
|
253 |
return $msg;
|
|
|
254 |
}
|
|
|
255 |
}
|
|
|
256 |
?>
|