00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 define('VALID_NOT_EMPTY', '/.+/');
00034
00035
00036
00037 define('VALID_NUMBER', '/^[-+]?\\b[0-9]*\\.?[0-9]+\\b$/');
00038
00039
00040
00041 define('VALID_EMAIL', "/^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[a-z]{2,4}|museum|travel)$/i");
00042
00043
00044
00045 define('VALID_YEAR', '/^[12][0-9]{3}$/');
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 class Validation extends Object {
00056
00057
00058
00059
00060
00061
00062 var $check = null;
00063
00064
00065
00066
00067
00068
00069
00070 var $regex = null;
00071
00072
00073
00074
00075
00076
00077 var $__pattern = array(
00078 'ip' => '(?:(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])',
00079 'hostname' => '(?:[a-z0-9][-a-z0-9]*\.)*(?:[a-z0-9][-a-z0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,4}|museum|travel)'
00080 );
00081
00082
00083
00084
00085
00086
00087
00088 var $country = null;
00089
00090
00091
00092
00093
00094
00095 var $deep = null;
00096
00097
00098
00099
00100
00101
00102 var $type = null;
00103
00104
00105
00106
00107
00108
00109
00110 var $errors = array();
00111
00112
00113
00114
00115
00116
00117
00118 function &getInstance() {
00119 static $instance = array();
00120
00121 if (!$instance) {
00122 $instance[0] =& new Validation();
00123 }
00124 return $instance[0];
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 function notEmpty($check) {
00139 $_this =& Validation::getInstance();
00140 $_this->__reset();
00141 $_this->check = $check;
00142
00143 if (is_array($check)) {
00144 $_this->_extract($check);
00145 }
00146
00147 if (empty($_this->check) && $_this->check != '0') {
00148 return false;
00149 }
00150 $_this->regex = '/[^\s]+/m';
00151 return $_this->_check();
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 function alphaNumeric($check) {
00166 $_this =& Validation::getInstance();
00167 $_this->__reset();
00168 $_this->check = $check;
00169
00170 if (is_array($check)) {
00171 $_this->_extract($check);
00172 }
00173
00174 if (empty($_this->check) && $_this->check != '0') {
00175 return false;
00176 }
00177 $_this->regex = '/^[\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]+$/mu';
00178 return $_this->_check();
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 function between($check, $min, $max) {
00192 $length = strlen($check);
00193 return ($length >= $min && $length <= $max);
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 function blank($check) {
00207 $_this =& Validation::getInstance();
00208 $_this->__reset();
00209 $_this->check = $check;
00210
00211 if (is_array($check)) {
00212 $_this->_extract($check);
00213 }
00214
00215 $_this->regex = '/[^\\s]/';
00216 return !$_this->_check();
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 function cc($check, $type = 'fast', $deep = false, $regex = null) {
00233 $_this =& Validation::getInstance();
00234 $_this->__reset();
00235 $_this->check = $check;
00236 $_this->type = $type;
00237 $_this->deep = $deep;
00238 $_this->regex = $regex;
00239
00240 if (is_array($check)) {
00241 $_this->_extract($check);
00242 }
00243 $_this->check = str_replace(array('-', ' '), '', $_this->check);
00244
00245 if (strlen($_this->check) < 13) {
00246 return false;
00247 }
00248
00249 if (!is_null($_this->regex)) {
00250 if ($_this->_check()) {
00251 return $_this->_luhn();
00252 }
00253 }
00254 $cards = array('all' => array('amex' => '/^3[4|7]\\d{13}$/',
00255 'bankcard' => '/^56(10\\d\\d|022[1-5])\\d{10}$/',
00256 'diners' => '/^(?:3(0[0-5]|[68]\\d)\\d{11})|(?:5[1-5]\\d{14})$/',
00257 'disc' => '/^(?:6011|650\\d)\\d{12}$/',
00258 'electron' => '/^(?:417500|4917\\d{2}|4913\\d{2})\\d{10}$/',
00259 'enroute' => '/^2(?:014|149)\\d{11}$/',
00260 'jcb' => '/^(3\\d{4}|2100|1800)\\d{11}$/',
00261 'maestro' => '/^(?:5020|6\\d{3})\\d{12}$/',
00262 'mc' => '/^5[1-5]\\d{14}$/',
00263 'solo' => '/^(6334[5-9][0-9]|6767[0-9]{2})\\d{10}(\\d{2,3})?$/',
00264 'switch' => '/^(?:49(03(0[2-9]|3[5-9])|11(0[1-2]|7[4-9]|8[1-2])|36[0-9]{2})\\d{10}(\\d{2,3})?)|(?:564182\\d{10}(\\d{2,3})?)|(6(3(33[0-4][0-9])|759[0-9]{2})\\d{10}(\\d{2,3})?)$/',
00265 'visa' => '/^4\\d{12}(\\d{3})?$/',
00266 'voyager' => '/^8699[0-9]{11}$/'),
00267 'fast' => '/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$/');
00268
00269 if (is_array($_this->type)) {
00270 foreach ($_this->type as $value) {
00271 $_this->regex = $cards['all'][strtolower($value)];
00272
00273 if ($_this->_check()) {
00274 return $_this->_luhn();
00275 }
00276 }
00277 } elseif ($_this->type == 'all') {
00278 foreach ($cards['all'] as $value) {
00279 $_this->regex = $value;
00280
00281 if ($_this->_check()) {
00282 return $_this->_luhn();
00283 }
00284 }
00285 } else {
00286 $_this->regex = $cards['fast'];
00287
00288 if ($_this->_check()) {
00289 return $_this->_luhn();
00290 }
00291 }
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 function comparison($check1, $operator = null, $check2 = null) {
00306 if (is_array($check1)) {
00307 extract($check1, EXTR_OVERWRITE);
00308 }
00309 $operator = str_replace(array(' ', "\t", "\n", "\r", "\0", "\x0B"), '', strtolower($operator));
00310
00311 switch ($operator) {
00312 case 'isgreater':
00313 case '>':
00314 if ($check1 > $check2) {
00315 return true;
00316 }
00317 break;
00318 case 'isless':
00319 case '<':
00320 if ($check1 < $check2) {
00321 return true;
00322 }
00323 break;
00324 case 'greaterorequal':
00325 case '>=':
00326 if ($check1 >= $check2) {
00327 return true;
00328 }
00329 break;
00330 case 'lessorequal':
00331 case '<=':
00332 if ($check1 <= $check2) {
00333 return true;
00334 }
00335 break;
00336 case 'equalto':
00337 case '==':
00338 if ($check1 == $check2) {
00339 return true;
00340 }
00341 break;
00342 case 'notequal':
00343 case '!=':
00344 if ($check1 != $check2) {
00345 return true;
00346 }
00347 break;
00348 default:
00349 $_this =& Validation::getInstance();
00350 $_this->errors[] = __('You must define the $operator parameter for Validation::comparison()', true);
00351 break;
00352 }
00353 return false;
00354 }
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 function custom($check, $regex = null) {
00365 $_this =& Validation::getInstance();
00366 $_this->__reset();
00367 $_this->check = $check;
00368 $_this->regex = $regex;
00369 if (is_array($check)) {
00370 $_this->_extract($check);
00371 }
00372 if ($_this->regex === null) {
00373 $_this->errors[] = __('You must define a regular expression for Validation::custom()', true);
00374 return false;
00375 }
00376 return $_this->_check();
00377 }
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395 function date($check, $format = 'ymd', $regex = null) {
00396 $_this =& Validation::getInstance();
00397 $_this->__reset();
00398 $_this->check = $check;
00399 $_this->regex = $regex;
00400
00401 if (!is_null($_this->regex)) {
00402 return $_this->_check();
00403 }
00404
00405 $regex['dmy'] = '%^(?:(?:31(\\/|-|\\.|\\x20)(?:0?[13578]|1[02]))\\1|(?:(?:29|30)(\\/|-|\\.|\\x20)(?:0?[1,3-9]|1[0-2])\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:29(\\/|-|\\.|\\x20)0?2\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\\d|2[0-8])(\\/|-|\\.|\\x20)(?:(?:0?[1-9])|(?:1[0-2]))\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%';
00406 $regex['mdy'] = '%^(?:(?:(?:0?[13578]|1[02])(\\/|-|\\.|\\x20)31)\\1|(?:(?:0?[13-9]|1[0-2])(\\/|-|\\.|\\x20)(?:29|30)\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:0?2(\\/|-|\\.|\\x20)29\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\\/|-|\\.|\\x20)(?:0?[1-9]|1\\d|2[0-8])\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%';
00407 $regex['ymd'] = '%^(?:(?:(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\\/|-|\\.|\\x20)(?:0?2\\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\\d)?\\d{2})(\\/|-|\\.|\\x20)(?:(?:(?:0?[13578]|1[02])\\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\\2(?:0?[1-9]|1\\d|2[0-8]))))$%';
00408 $regex['dMy'] = '/^((31(?!\\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\\b|t)t?|Nov)(ember)?)))|((30|29)(?!\\ Feb(ruary)?))|(29(?=\\ Feb(ruary)?\\ (((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\\d|2[0-8])\\ (Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)\\ ((1[6-9]|[2-9]\\d)\\d{2})$/';
00409 $regex['Mdy'] = '/^(?:(((Jan(uary)?|Ma(r(ch)?|y)|Jul(y)?|Aug(ust)?|Oct(ober)?|Dec(ember)?)\\ 31)|((Jan(uary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sept|Nov|Dec)(ember)?)\\ (0?[1-9]|([12]\\d)|30))|(Feb(ruary)?\\ (0?[1-9]|1\\d|2[0-8]|(29(?=,?\\ ((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))))\\,?\\ ((1[6-9]|[2-9]\\d)\\d{2}))$/';
00410 $regex['My'] = '%^(Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)[ /]((1[6-9]|[2-9]\\d)\\d{2})$%';
00411 $regex['my'] = '%^(((0[123456789]|10|11|12)([- /.])(([1][9][0-9][0-9])|([2][0-9][0-9][0-9]))))$%';
00412
00413 $format = (is_array($format)) ? array_values($format) : array($format);
00414 foreach ($format as $key) {
00415 $_this->regex = $regex[$key];
00416
00417 if ($_this->_check() === true) {
00418 return true;
00419 }
00420 }
00421 return false;
00422 }
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434 function time($check) {
00435 $_this =& Validation::getInstance();
00436 $_this->__reset();
00437 $_this->check = $check;
00438 $_this->regex = '%^((0?[1-9]|1[012])(:[0-5]\d){0,2}([AP]M|[ap]m))$|^([01]\d|2[0-3])(:[0-5]\d){0,2}$%';
00439 return $_this->_check();
00440 }
00441
00442
00443
00444
00445
00446
00447
00448
00449 function boolean($check) {
00450 $booleanList = array(0, 1, '0', '1', true, false);
00451 return in_array($check, $booleanList, true);
00452 }
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464 function decimal($check, $places = null, $regex = null) {
00465 $_this =& Validation::getInstance();
00466 $_this->__reset();
00467 $_this->regex = $regex;
00468 $_this->check = $check;
00469
00470 if (is_null($_this->regex)) {
00471 if (is_null($places)) {
00472 $_this->regex = '/^[-+]?[0-9]*\\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?$/';
00473 } else {
00474 $_this->regex = '/^[-+]?[0-9]*\\.{1}[0-9]{'.$places.'}$/';
00475 }
00476 }
00477 return $_this->_check();
00478 }
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488 function email($check, $deep = false, $regex = null) {
00489 $_this =& Validation::getInstance();
00490 $_this->__reset();
00491 $_this->check = $check;
00492 $_this->regex = $regex;
00493 $_this->deep = $deep;
00494
00495 if (is_array($check)) {
00496 $_this->_extract($check);
00497 }
00498
00499 if (is_null($_this->regex)) {
00500 $_this->regex = '/^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@' . $_this->__pattern['hostname'] . '$/i';
00501 }
00502 $return = $_this->_check();
00503
00504 if ($_this->deep === false || $_this->deep === null) {
00505 return $return;
00506 }
00507
00508 if ($return === true && preg_match('/@(' . $_this->__pattern['hostname'] . ')$/i', $_this->check, $regs)) {
00509 $host = gethostbynamel($regs[1]);
00510 return is_array($host);
00511 }
00512 return false;
00513 }
00514
00515
00516
00517
00518
00519
00520
00521
00522 function equalTo($check, $comparedTo) {
00523 return ($check === $comparedTo);
00524 }
00525
00526
00527
00528
00529
00530
00531
00532
00533 function extension($check, $extensions = array('gif', 'jpeg', 'png', 'jpg')) {
00534 if (is_array($check)) {
00535 return Validation::extension(array_shift($check), $extensions);
00536 }
00537 $extension = strtolower(array_pop(explode('.', $check)));
00538 foreach ($extensions as $value) {
00539 if ($extension == strtolower($value)) {
00540 return true;
00541 }
00542 }
00543 return false;
00544 }
00545
00546
00547
00548
00549
00550
00551
00552 function file($check) {
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563 }
00564
00565
00566
00567
00568
00569
00570
00571 function ip($check) {
00572 $_this =& Validation::getInstance();
00573 $_this->check = $check;
00574 $_this->regex = '/^' . $_this->__pattern['ip'] . '$/';
00575 return $_this->_check();
00576 }
00577
00578
00579
00580
00581
00582
00583
00584
00585 function minLength($check, $min) {
00586 $length = strlen($check);
00587 return ($length >= $min);
00588 }
00589
00590
00591
00592
00593
00594
00595
00596
00597 function maxLength($check, $max) {
00598 $length = strlen($check);
00599 return ($length <= $max);
00600 }
00601
00602
00603
00604
00605
00606
00607
00608
00609 function money($check, $symbolPosition = 'left') {
00610 $_this =& Validation::getInstance();
00611 $_this->check = $check;
00612
00613 if ($symbolPosition == 'right') {
00614 $_this->regex = '/^(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?(?<!\x{00a2})\p{Sc}?$/u';
00615 } else {
00616 $_this->regex = '/^(?!\x{00a2})\p{Sc}?(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?$/u';
00617 }
00618 return $_this->_check();
00619 }
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632 function multiple($check, $options = array()) {
00633 $defaults = array('in' => null, 'max' => null, 'min' => null);
00634 $options = array_merge($defaults, $options);
00635 $check = array_filter((array)$check);
00636 if (empty($check)) {
00637 return false;
00638 }
00639 if ($options['max'] && sizeof($check) > $options['max']) {
00640 return false;
00641 }
00642 if ($options['min'] && sizeof($check) < $options['min']) {
00643 return false;
00644 }
00645 if ($options['in'] && is_array($options['in'])) {
00646 foreach ($check as $val) {
00647 if (!in_array($val, $options['in'])) {
00648 return false;
00649 }
00650 }
00651 }
00652 return true;
00653 }
00654
00655
00656
00657
00658
00659
00660
00661 function numeric($check) {
00662 return is_numeric($check);
00663 }
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673 function phone($check, $regex = null, $country = 'all') {
00674 $_this =& Validation::getInstance();
00675 $_this->check = $check;
00676 $_this->regex = $regex;
00677 $_this->country = $country;
00678 if (is_array($check)) {
00679 $_this->_extract($check);
00680 }
00681
00682 if (is_null($_this->regex)) {
00683 switch ($_this->country) {
00684 case 'us':
00685
00686 default:
00687 $_this->regex = '/^(?:\+?1)?[-. ]?\\(?[2-9][0-8][0-9]\\)?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}$/';
00688 break;
00689 }
00690 }
00691 return $_this->_check();
00692 }
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702 function postal($check, $regex = null, $country = null) {
00703 $_this =& Validation::getInstance();
00704 $_this->check = $check;
00705 $_this->regex = $regex;
00706 $_this->country = $country;
00707 if (is_array($check)) {
00708 $_this->_extract($check);
00709 }
00710
00711 if (is_null($_this->regex)) {
00712 switch ($_this->country) {
00713 case 'uk':
00714 $_this->regex = '/\\A\\b[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2}\\b\\z/i';
00715 break;
00716 case 'ca':
00717 $_this->regex = '/\\A\\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] [0-9][A-Z][0-9]\\b\\z/i';
00718 break;
00719 case 'it':
00720 case 'de':
00721 $_this->regex = '/^[0-9]{5}$/i';
00722 break;
00723 case 'be':
00724 $_this->regex = '/^[1-9]{1}[0-9]{3}$/i';
00725 break;
00726 case 'us':
00727 default:
00728 $_this->regex = '/\\A\\b[0-9]{5}(?:-[0-9]{4})?\\b\\z/i';
00729 break;
00730 }
00731 }
00732 return $_this->_check();
00733 }
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745 function range($check, $lower = null, $upper = null ) {
00746 if (!is_numeric($check)) {
00747 return false;
00748 }
00749 if (isset($lower) && isset($upper)) {
00750 return ($check > $lower && $check < $upper);
00751 }
00752 return is_finite($check);
00753 }
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763 function ssn($check, $regex = null, $country = null) {
00764 $_this =& Validation::getInstance();
00765 $_this->check = $check;
00766 $_this->regex = $regex;
00767 $_this->country = $country;
00768 if (is_array($check)) {
00769 $_this->_extract($check);
00770 }
00771
00772 if (is_null($_this->regex)) {
00773 switch ($_this->country) {
00774 case 'dk':
00775 $_this->regex = '/\\A\\b[0-9]{6}-[0-9]{4}\\b\\z/i';
00776 break;
00777 case 'nl':
00778 $_this->regex = '/\\A\\b[0-9]{9}\\b\\z/i';
00779 break;
00780 case 'us':
00781 default:
00782 $_this->regex = '/\\A\\b[0-9]{3}-[0-9]{2}-[0-9]{4}\\b\\z/i';
00783 break;
00784 }
00785 }
00786 return $_this->_check();
00787 }
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805 function url($check, $strict = false) {
00806 $_this =& Validation::getInstance();
00807 $_this->check = $check;
00808 $validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=') . '\/0-9a-z]|(%[0-9a-f]{2}))';
00809 $_this->regex = '/^(?:(?:https?|ftps?|file|news|gopher):\/\/)' . ife($strict, '', '?') .
00810 '(?:' . $_this->__pattern['ip'] . '|' . $_this->__pattern['hostname'] . ')(?::[1-9][0-9]{0,3})?' .
00811 '(?:\/?|\/' . $validChars . '*)?' .
00812 '(?:\?' . $validChars . '*)?' .
00813 '(?:#' . $validChars . '*)?$/i';
00814 return $_this->_check();
00815 }
00816
00817
00818
00819
00820
00821
00822
00823
00824 function inList($check, $list) {
00825 return in_array($check, $list);
00826 }
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837 function userDefined($check, $object, $method, $args = null) {
00838 return call_user_func_array(array(&$object, $method), array($check, $args));
00839 }
00840
00841
00842
00843
00844
00845
00846 function _check() {
00847 $_this =& Validation::getInstance();
00848 if (preg_match($_this->regex, $_this->check)) {
00849 $_this->error[] = false;
00850 return true;
00851 } else {
00852 $_this->error[] = true;
00853 return false;
00854 }
00855 }
00856
00857
00858
00859
00860
00861
00862
00863
00864 function _extract($params) {
00865 $_this =& Validation::getInstance();
00866 extract($params, EXTR_OVERWRITE);
00867
00868 if (isset($check)) {
00869 $_this->check = $check;
00870 }
00871 if (isset($regex)) {
00872 $_this->regex = $regex;
00873 }
00874 if (isset($country)) {
00875 $_this->country = strtolower($country);
00876 }
00877 if (isset($deep)) {
00878 $_this->deep = $deep;
00879 }
00880 if (isset($type)) {
00881 $_this->type = $type;
00882 }
00883 }
00884
00885
00886
00887
00888
00889
00890
00891 function _luhn() {
00892 $_this =& Validation::getInstance();
00893 if ($_this->deep !== true) {
00894 return true;
00895 }
00896 if ($_this->check == 0) {
00897 return false;
00898 }
00899 $sum = 0;
00900 $length = strlen($_this->check);
00901
00902 for ($position = 1 - ($length % 2); $position < $length; $position += 2) {
00903 $sum += $_this->check[$position];
00904 }
00905
00906 for ($position = ($length % 2); $position < $length; $position += 2) {
00907 $number = $_this->check[$position] * 2;
00908 $sum += ($number < 10) ? $number : $number - 9;
00909 }
00910
00911 return ($sum % 10 == 0);
00912 }
00913
00914
00915
00916
00917
00918
00919 function __reset() {
00920 $this->check = null;
00921 $this->regex = null;
00922 $this->country = null;
00923 $this->deep = null;
00924 $this->type = null;
00925 $this->error = array();
00926 $this->errors = array();
00927 }
00928 }
00929 ?>