1: <?php
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: define('VALID_NOT_EMPTY', '/.+/');
33: 34: 35:
36: define('VALID_NUMBER', '/^[-+]?\\b[0-9]*\\.?[0-9]+\\b$/');
37: 38: 39:
40: 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");
41: 42: 43:
44: define('VALID_YEAR', '/^[12][0-9]{3}$/');
45: 46: 47: 48: 49: 50: 51: 52: 53:
54: class Validation extends Object {
55: 56: 57: 58: 59: 60:
61: var $check = null;
62: 63: 64: 65: 66: 67: 68:
69: var $regex = null;
70: 71: 72: 73: 74: 75:
76: var $__pattern = array(
77: '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])',
78: 'hostname' => '(?:[a-z0-9][-a-z0-9]*\.)*(?:[a-z0-9][-a-z0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,4}|museum|travel)'
79: );
80: 81: 82: 83: 84: 85: 86:
87: var $country = null;
88: 89: 90: 91: 92: 93:
94: var $deep = null;
95: 96: 97: 98: 99: 100:
101: var $type = null;
102: 103: 104: 105: 106: 107: 108:
109: var $errors = array();
110: 111: 112: 113: 114: 115: 116:
117: function &getInstance() {
118: static $instance = array();
119:
120: if (!$instance) {
121: $instance[0] =& new Validation();
122: }
123: return $instance[0];
124: }
125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136:
137: function notEmpty($check) {
138: $_this =& Validation::getInstance();
139: $_this->__reset();
140: $_this->check = $check;
141:
142: if (is_array($check)) {
143: $_this->_extract($check);
144: }
145:
146: if (empty($_this->check) && $_this->check != '0') {
147: return false;
148: }
149: $_this->regex = '/[^\s]+/m';
150: return $_this->_check();
151: }
152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163:
164: function alphaNumeric($check) {
165: $_this =& Validation::getInstance();
166: $_this->__reset();
167: $_this->check = $check;
168:
169: if (is_array($check)) {
170: $_this->_extract($check);
171: }
172:
173: if (empty($_this->check) && $_this->check != '0') {
174: return false;
175: }
176: $_this->regex = '/^[\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]+$/mu';
177: return $_this->_check();
178: }
179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189:
190: function between($check, $min, $max) {
191: $length = strlen($check);
192: return ($length >= $min && $length <= $max);
193: }
194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204:
205: function blank($check) {
206: $_this =& Validation::getInstance();
207: $_this->__reset();
208: $_this->check = $check;
209:
210: if (is_array($check)) {
211: $_this->_extract($check);
212: }
213:
214: $_this->regex = '/[^\\s]/';
215: return !$_this->_check();
216: }
217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230:
231: function cc($check, $type = 'fast', $deep = false, $regex = null) {
232: $_this =& Validation::getInstance();
233: $_this->__reset();
234: $_this->check = $check;
235: $_this->type = $type;
236: $_this->deep = $deep;
237: $_this->regex = $regex;
238:
239: if (is_array($check)) {
240: $_this->_extract($check);
241: }
242: $_this->check = str_replace(array('-', ' '), '', $_this->check);
243:
244: if (strlen($_this->check) < 13) {
245: return false;
246: }
247:
248: if (!is_null($_this->regex)) {
249: if ($_this->_check()) {
250: return $_this->_luhn();
251: }
252: }
253: $cards = array('all' => array('amex' => '/^3[4|7]\\d{13}$/',
254: 'bankcard' => '/^56(10\\d\\d|022[1-5])\\d{10}$/',
255: 'diners' => '/^(?:3(0[0-5]|[68]\\d)\\d{11})|(?:5[1-5]\\d{14})$/',
256: 'disc' => '/^(?:6011|650\\d)\\d{12}$/',
257: 'electron' => '/^(?:417500|4917\\d{2}|4913\\d{2})\\d{10}$/',
258: 'enroute' => '/^2(?:014|149)\\d{11}$/',
259: 'jcb' => '/^(3\\d{4}|2100|1800)\\d{11}$/',
260: 'maestro' => '/^(?:5020|6\\d{3})\\d{12}$/',
261: 'mc' => '/^5[1-5]\\d{14}$/',
262: 'solo' => '/^(6334[5-9][0-9]|6767[0-9]{2})\\d{10}(\\d{2,3})?$/',
263: '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})?)$/',
264: 'visa' => '/^4\\d{12}(\\d{3})?$/',
265: 'voyager' => '/^8699[0-9]{11}$/'),
266: '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})$/');
267:
268: if (is_array($_this->type)) {
269: foreach ($_this->type as $value) {
270: $_this->regex = $cards['all'][strtolower($value)];
271:
272: if ($_this->_check()) {
273: return $_this->_luhn();
274: }
275: }
276: } elseif ($_this->type == 'all') {
277: foreach ($cards['all'] as $value) {
278: $_this->regex = $value;
279:
280: if ($_this->_check()) {
281: return $_this->_luhn();
282: }
283: }
284: } else {
285: $_this->regex = $cards['fast'];
286:
287: if ($_this->_check()) {
288: return $_this->_luhn();
289: }
290: }
291: }
292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303:
304: function comparison($check1, $operator = null, $check2 = null) {
305: if (is_array($check1)) {
306: extract($check1, EXTR_OVERWRITE);
307: }
308: $operator = str_replace(array(' ', "\t", "\n", "\r", "\0", "\x0B"), '', strtolower($operator));
309:
310: switch ($operator) {
311: case 'isgreater':
312: case '>':
313: if ($check1 > $check2) {
314: return true;
315: }
316: break;
317: case 'isless':
318: case '<':
319: if ($check1 < $check2) {
320: return true;
321: }
322: break;
323: case 'greaterorequal':
324: case '>=':
325: if ($check1 >= $check2) {
326: return true;
327: }
328: break;
329: case 'lessorequal':
330: case '<=':
331: if ($check1 <= $check2) {
332: return true;
333: }
334: break;
335: case 'equalto':
336: case '==':
337: if ($check1 == $check2) {
338: return true;
339: }
340: break;
341: case 'notequal':
342: case '!=':
343: if ($check1 != $check2) {
344: return true;
345: }
346: break;
347: default:
348: $_this =& Validation::getInstance();
349: $_this->errors[] = __('You must define the $operator parameter for Validation::comparison()', true);
350: break;
351: }
352: return false;
353: }
354: 355: 356: 357: 358: 359: 360: 361: 362:
363: function custom($check, $regex = null) {
364: $_this =& Validation::getInstance();
365: $_this->__reset();
366: $_this->check = $check;
367: $_this->regex = $regex;
368: if (is_array($check)) {
369: $_this->_extract($check);
370: }
371: if ($_this->regex === null) {
372: $_this->errors[] = __('You must define a regular expression for Validation::custom()', true);
373: return false;
374: }
375: return $_this->_check();
376: }
377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393:
394: function date($check, $format = 'ymd', $regex = null) {
395: $_this =& Validation::getInstance();
396: $_this->__reset();
397: $_this->check = $check;
398: $_this->regex = $regex;
399:
400: if (!is_null($_this->regex)) {
401: return $_this->_check();
402: }
403:
404: $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})$%';
405: $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})$%';
406: $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]))))$%';
407: $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})$/';
408: $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}))$/';
409: $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})$%';
410: $regex['my'] = '%^(((0[123456789]|10|11|12)([- /.])(([1][9][0-9][0-9])|([2][0-9][0-9][0-9]))))$%';
411:
412: $format = (is_array($format)) ? array_values($format) : array($format);
413: foreach ($format as $key) {
414: $_this->regex = $regex[$key];
415:
416: if ($_this->_check() === true) {
417: return true;
418: }
419: }
420: return false;
421: }
422:
423: 424: 425: 426: 427: 428: 429: 430: 431:
432:
433: function time($check) {
434: $_this =& Validation::getInstance();
435: $_this->__reset();
436: $_this->check = $check;
437: $_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}$%';
438: return $_this->_check();
439: }
440:
441: 442: 443: 444: 445: 446: 447:
448: function boolean($check) {
449: $booleanList = array(0, 1, '0', '1', true, false);
450: return in_array($check, $booleanList, true);
451: }
452:
453: 454: 455: 456: 457: 458: 459: 460: 461: 462:
463: function decimal($check, $places = null, $regex = null) {
464: $_this =& Validation::getInstance();
465: $_this->__reset();
466: $_this->regex = $regex;
467: $_this->check = $check;
468:
469: if (is_null($_this->regex)) {
470: if (is_null($places)) {
471: $_this->regex = '/^[-+]?[0-9]*\\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?$/';
472: } else {
473: $_this->regex = '/^[-+]?[0-9]*\\.{1}[0-9]{'.$places.'}$/';
474: }
475: }
476: return $_this->_check();
477: }
478: 479: 480: 481: 482: 483: 484: 485: 486:
487: function email($check, $deep = false, $regex = null) {
488: $_this =& Validation::getInstance();
489: $_this->__reset();
490: $_this->check = $check;
491: $_this->regex = $regex;
492: $_this->deep = $deep;
493:
494: if (is_array($check)) {
495: $_this->_extract($check);
496: }
497:
498: if (is_null($_this->regex)) {
499: $_this->regex = '/^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@' . $_this->__pattern['hostname'] . '$/i';
500: }
501: $return = $_this->_check();
502:
503: if ($_this->deep === false || $_this->deep === null) {
504: return $return;
505: }
506:
507: if ($return === true && preg_match('/@(' . $_this->__pattern['hostname'] . ')$/i', $_this->check, $regs)) {
508: $host = gethostbynamel($regs[1]);
509: return is_array($host);
510: }
511: return false;
512: }
513: 514: 515: 516: 517: 518: 519: 520:
521: function equalTo($check, $comparedTo) {
522: return ($check === $comparedTo);
523: }
524: 525: 526: 527: 528: 529: 530: 531:
532: function extension($check, $extensions = array('gif', 'jpeg', 'png', 'jpg')) {
533: if (is_array($check)) {
534: return Validation::extension(array_shift($check), $extensions);
535: }
536: $extension = strtolower(array_pop(explode('.', $check)));
537: foreach ($extensions as $value) {
538: if ($extension == strtolower($value)) {
539: return true;
540: }
541: }
542: return false;
543: }
544: 545: 546: 547: 548: 549: 550:
551: function file($check) {
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562: }
563: 564: 565: 566: 567: 568: 569:
570: function ip($check) {
571: $_this =& Validation::getInstance();
572: $_this->check = $check;
573: $_this->regex = '/^' . $_this->__pattern['ip'] . '$/';
574: return $_this->_check();
575: }
576: 577: 578: 579: 580: 581: 582: 583:
584: function minLength($check, $min) {
585: $length = strlen($check);
586: return ($length >= $min);
587: }
588: 589: 590: 591: 592: 593: 594: 595:
596: function maxLength($check, $max) {
597: $length = strlen($check);
598: return ($length <= $max);
599: }
600: 601: 602: 603: 604: 605: 606: 607:
608: function money($check, $symbolPosition = 'left') {
609: $_this =& Validation::getInstance();
610: $_this->check = $check;
611:
612: if ($symbolPosition == 'right') {
613: $_this->regex = '/^(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?(?<!\x{00a2})\p{Sc}?$/u';
614: } else {
615: $_this->regex = '/^(?!\x{00a2})\p{Sc}?(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?$/u';
616: }
617: return $_this->_check();
618: }
619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630:
631: function multiple($check, $options = array()) {
632: $defaults = array('in' => null, 'max' => null, 'min' => null);
633: $options = array_merge($defaults, $options);
634: $check = array_filter((array)$check);
635: if (empty($check)) {
636: return false;
637: }
638: if ($options['max'] && count($check) > $options['max']) {
639: return false;
640: }
641: if ($options['min'] && count($check) < $options['min']) {
642: return false;
643: }
644: if ($options['in'] && is_array($options['in'])) {
645: foreach ($check as $val) {
646: if (!in_array($val, $options['in'])) {
647: return false;
648: }
649: }
650: }
651: return true;
652: }
653: 654: 655: 656: 657: 658: 659:
660: function numeric($check) {
661: return is_numeric($check);
662: }
663: 664: 665: 666: 667: 668: 669: 670: 671:
672: function phone($check, $regex = null, $country = 'all') {
673: $_this =& Validation::getInstance();
674: $_this->check = $check;
675: $_this->regex = $regex;
676: $_this->country = $country;
677: if (is_array($check)) {
678: $_this->_extract($check);
679: }
680:
681: if (is_null($_this->regex)) {
682: switch ($_this->country) {
683: case 'us':
684:
685: default:
686: $_this->regex = '/^(?:\+?1)?[-. ]?\\(?[2-9][0-8][0-9]\\)?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}$/';
687: break;
688: }
689: }
690: return $_this->_check();
691: }
692: 693: 694: 695: 696: 697: 698: 699: 700:
701: function postal($check, $regex = null, $country = null) {
702: $_this =& Validation::getInstance();
703: $_this->check = $check;
704: $_this->regex = $regex;
705: $_this->country = $country;
706: if (is_array($check)) {
707: $_this->_extract($check);
708: }
709:
710: if (is_null($_this->regex)) {
711: switch ($_this->country) {
712: case 'uk':
713: $_this->regex = '/\\A\\b[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2}\\b\\z/i';
714: break;
715: case 'ca':
716: $_this->regex = '/\\A\\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] ?[0-9][A-Z][0-9]\\b\\z/i';
717: break;
718: case 'it':
719: case 'de':
720: $_this->regex = '/^[0-9]{5}$/i';
721: break;
722: case 'be':
723: $_this->regex = '/^[1-9]{1}[0-9]{3}$/i';
724: break;
725: case 'us':
726: default:
727: $_this->regex = '/\\A\\b[0-9]{5}(?:-[0-9]{4})?\\b\\z/i';
728: break;
729: }
730: }
731: return $_this->_check();
732: }
733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743:
744: function range($check, $lower = null, $upper = null ) {
745: if (!is_numeric($check)) {
746: return false;
747: }
748: if (isset($lower) && isset($upper)) {
749: return ($check > $lower && $check < $upper);
750: }
751: return is_finite($check);
752: }
753: 754: 755: 756: 757: 758: 759: 760: 761:
762: function ssn($check, $regex = null, $country = null) {
763: $_this =& Validation::getInstance();
764: $_this->check = $check;
765: $_this->regex = $regex;
766: $_this->country = $country;
767: if (is_array($check)) {
768: $_this->_extract($check);
769: }
770:
771: if (is_null($_this->regex)) {
772: switch ($_this->country) {
773: case 'dk':
774: $_this->regex = '/\\A\\b[0-9]{6}-[0-9]{4}\\b\\z/i';
775: break;
776: case 'nl':
777: $_this->regex = '/\\A\\b[0-9]{9}\\b\\z/i';
778: break;
779: case 'us':
780: default:
781: $_this->regex = '/\\A\\b[0-9]{3}-[0-9]{2}-[0-9]{4}\\b\\z/i';
782: break;
783: }
784: }
785: return $_this->_check();
786: }
787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803:
804: function url($check, $strict = false) {
805: $_this =& Validation::getInstance();
806: $_this->check = $check;
807: $validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=') . '\/0-9a-z]|(%[0-9a-f]{2}))';
808: $_this->regex = '/^(?:(?:https?|ftps?|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') .
809: '(?:' . $_this->__pattern['ip'] . '|' . $_this->__pattern['hostname'] . ')(?::[1-9][0-9]{0,3})?' .
810: '(?:\/?|\/' . $validChars . '*)?' .
811: '(?:\?' . $validChars . '*)?' .
812: '(?:#' . $validChars . '*)?$/i';
813: return $_this->_check();
814: }
815: 816: 817: 818: 819: 820: 821: 822:
823: function inList($check, $list) {
824: return in_array($check, $list);
825: }
826: 827: 828: 829: 830: 831: 832: 833: 834: 835:
836: function userDefined($check, $object, $method, $args = null) {
837: return call_user_func_array(array(&$object, $method), array($check, $args));
838: }
839: 840: 841: 842: 843: 844:
845: function _check() {
846: $_this =& Validation::getInstance();
847: if (preg_match($_this->regex, $_this->check)) {
848: $_this->error[] = false;
849: return true;
850: } else {
851: $_this->error[] = true;
852: return false;
853: }
854: }
855: 856: 857: 858: 859: 860: 861: 862:
863: function _extract($params) {
864: $_this =& Validation::getInstance();
865: extract($params, EXTR_OVERWRITE);
866:
867: if (isset($check)) {
868: $_this->check = $check;
869: }
870: if (isset($regex)) {
871: $_this->regex = $regex;
872: }
873: if (isset($country)) {
874: $_this->country = strtolower($country);
875: }
876: if (isset($deep)) {
877: $_this->deep = $deep;
878: }
879: if (isset($type)) {
880: $_this->type = $type;
881: }
882: }
883: 884: 885: 886: 887: 888: 889:
890: function _luhn() {
891: $_this =& Validation::getInstance();
892: if ($_this->deep !== true) {
893: return true;
894: }
895: if ($_this->check == 0) {
896: return false;
897: }
898: $sum = 0;
899: $length = strlen($_this->check);
900:
901: for ($position = 1 - ($length % 2); $position < $length; $position += 2) {
902: $sum += $_this->check[$position];
903: }
904:
905: for ($position = ($length % 2); $position < $length; $position += 2) {
906: $number = $_this->check[$position] * 2;
907: $sum += ($number < 10) ? $number : $number - 9;
908: }
909:
910: return ($sum % 10 == 0);
911: }
912: 913: 914: 915: 916: 917:
918: function __reset() {
919: $this->check = null;
920: $this->regex = null;
921: $this->country = null;
922: $this->deep = null;
923: $this->type = null;
924: $this->error = array();
925: $this->errors = array();
926: }
927: }
928: ?>