Changeset 447 for branches/eli_branch/lib/Validator.inc.php
- Timestamp:
- Dec 13, 2013 11:24:08 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eli_branch/lib/Validator.inc.php
r439 r447 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 24 24 * Validator.inc.php 25 25 * 26 * The Validator class provides a methods for validating input against different criteria. 26 * The Validator class provides a methods for validating input against different criteria. 27 27 * All functions return true if the input passes the test. 28 28 * … … 31 31 */ 32 32 33 // Known credit card types.34 define('CC_TYPE_VISA', 1);35 define('CC_TYPE_MASTERCARD', 2);36 define('CC_TYPE_AMEX', 3);37 define('CC_TYPE_DISCOVER', 4);38 define('CC_TYPE_DINERS', 5);39 define('CC_TYPE_JCB', 6);40 41 // validateEmail return types.42 define('VALIDATE_EMAIL_SUCCESS', 0);43 define('VALIDATE_EMAIL_REGEX_FAIL', 1);44 define('VALIDATE_EMAIL_LENGTH_FAIL', 2);45 define('VALIDATE_EMAIL_MX_FAIL', 3);46 47 33 class Validator { 34 35 // Known credit card types. 36 const CC_TYPE_VISA = 1; 37 const CC_TYPE_MASTERCARD = 2; 38 const CC_TYPE_AMEX = 3; 39 const CC_TYPE_DISCOVER = 4; 40 const CC_TYPE_DINERS = 5; 41 const CC_TYPE_JCB = 6; 42 43 // Validator::validateEmail() return types. 44 const EMAIL_SUCCESS = 0; 45 const EMAIL_REGEX_FAIL = 1; 46 const EMAIL_LENGTH_FAIL = 2; 47 const EMAIL_MX_FAIL = 3; 48 48 49 49 /** … … 180 180 * @access public 181 181 * @param string $val The input data to validate.. 182 * @return const One of the constant values: V ALIDATE_EMAIL_SUCCESS|VALIDATE_EMAIL_REGEX_FAIL|VALIDATE_EMAIL_LENGTH_FAIL|VALIDATE_EMAIL_MX_FAIL182 * @return const One of the constant values: Validate::EMAIL_SUCCESS|Validate::EMAIL_REGEX_FAIL|Validate::EMAIL_LENGTH_FAIL|Validate::EMAIL_MX_FAIL 183 183 * @author Quinn Comendant <quinn@strangecode.com> 184 184 */ … … 190 190 // Test email address format. 191 191 if (!preg_match($e->getParam('regex'), $val, $e_parts)) { 192 return VALIDATE_EMAIL_REGEX_FAIL;193 } 194 192 return self::EMAIL_REGEX_FAIL; 193 } 194 195 195 // We have a match! Here are the captured subpatterns, on which further tests are run. 196 // The part before the @. 196 // The part before the @. 197 197 $local = $e_parts[2]; 198 198 199 // The part after the @. 199 // The part after the @. 200 200 // If domain is an IP [XXX.XXX.XXX.XXX] strip off the brackets. 201 201 $domain = $e_parts[3]{0} == '[' ? mb_substr($e_parts[3], 1, -1) : $e_parts[3]; … … 203 203 // Test length. 204 204 if (mb_strlen($local) > 64 || mb_strlen($domain) > 191) { 205 return VALIDATE_EMAIL_LENGTH_FAIL;205 return self::EMAIL_LENGTH_FAIL; 206 206 } 207 207 … … 210 210 if ((ip2long($domain) == '-1' || ip2long($domain) === false) && function_exists('checkdnsrr') && !checkdnsrr($domain . '.', 'MX') && gethostbyname($domain) == $domain) { 211 211 // FIXME: Do we care? 212 // return VALIDATE_EMAIL_MX_FAIL;213 } 214 215 return VALIDATE_EMAIL_SUCCESS;212 // return self::EMAIL_MX_FAIL; 213 } 214 215 return self::EMAIL_SUCCESS; 216 216 } 217 217 … … 225 225 { 226 226 $app =& App::getInstance(); 227 227 228 228 if ('' == trim($val)) { 229 229 // Don't be too bothered about empty strings. … … 257 257 // Perform card-specific checks, if applicable 258 258 switch ($cc_type) { 259 case CC_TYPE_VISA :259 case self::CC_TYPE_VISA : 260 260 $regex = '/^4\d{15}$|^4\d{12}$/'; 261 261 break; 262 case CC_TYPE_MASTERCARD :262 case self::CC_TYPE_MASTERCARD : 263 263 $regex = '/^5[1-5]\d{14}$/'; 264 264 break; 265 case CC_TYPE_AMEX :265 case self::CC_TYPE_AMEX : 266 266 $regex = '/^3[47]\d{13}$/'; 267 267 break; 268 case CC_TYPE_DISCOVER :268 case self::CC_TYPE_DISCOVER : 269 269 $regex = '/^6011\d{12}$/'; 270 270 break; 271 case CC_TYPE_DINERS :271 case self::CC_TYPE_DINERS : 272 272 $regex = '/^30[0-5]\d{11}$|^3[68]\d{12}$/'; 273 273 break; 274 case CC_TYPE_JCB :274 case self::CC_TYPE_JCB : 275 275 $regex = '/^3\d{15}$|^2131|1800\d{11}$/'; 276 276 break; … … 279 279 break; 280 280 } 281 281 282 282 if ('' != $regex && !preg_match($regex, $cc_num)) { 283 283 // Invalid format. … … 324 324 return false; 325 325 } 326 326 327 327 if (is_array($_FILES[$form_name]['name'])) { 328 328 foreach($_FILES[$form_name]['name'] as $f) { … … 336 336 } 337 337 } 338 338 339 339 return true; 340 340 }
Note: See TracChangeset
for help on using the changeset viewer.