Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Split Validate_AR/Validate

  • Loading branch information...
commit 738e05684b99d9753aec628733f7d82b782bd5d2 1 parent 9f22b5f
@CloCkWeRX CloCkWeRX authored
Showing with 0 additions and 57,239 deletions.
  1. +0 −34 README.ADD_LOCALE
  2. +0 −11 TODO
  3. +0 −1,149 Validate.php
  4. +0 −135 Validate/AT.php
  5. +0 −467 Validate/BE.php
  6. +0 −271 Validate/CA.php
  7. +0 −158 Validate/CH.php
  8. +0 −73 Validate/DE.php
  9. +0 −159 Validate/DK.php
  10. +0 −291 Validate/ES.php
  11. +0 −682 Validate/FI.php
  12. +0 −109 Validate/Finance.php
  13. +0 −260 Validate/Finance/CreditCard.php
  14. +0 −717 Validate/Finance/IBAN.php
  15. +0 −76 Validate/Finance/ISIN.php
  16. +0 −504 Validate/IE.php
  17. +0 −153 Validate/IR.php
  18. +0 −367 Validate/ISPN.php
  19. +0 −540 Validate/IT.php
  20. +0 −81 Validate/LI.php
  21. +0 −56 Validate/LU.php
  22. +0 −221 Validate/LV.php
  23. +0 −56 Validate/NO.php
  24. +0 −361 Validate/NZ.php
  25. +0 −101 Validate/SE.php
  26. +0 −242 Validate/UK.php
  27. +0 −320 Validate/UK/carReg.php
  28. +0 −583 Validate/US.php
  29. +0 −240 Validate/World.php
  30. +0 −297 Validate/esMX.php
  31. +0 −344 Validate/ptBR.php
  32. +0 −2,057 data/AT_postcodes.txt
  33. +0 −2,853 data/BE_postcodes.txt
  34. +0 −3,509 data/CH_postcodes.txt
  35. +0 −22 data/IE_postcodes.txt
  36. +0 −987 data/NZ_postcodes.txt
  37. +0 −29,111 data/esMX_postcodes.txt
  38. +0 −109 docs/Example_Locale.php
  39. +0 −73 docs/Validate_BE.txt
  40. +0 −55 docs/sample_multiple.php
  41. +0 −78 docs/validate_it_examples.php
  42. +0 −471 package.xml
  43. +0 −92 package_AT.xml
  44. +0 −162 package_BE.xml
  45. +0 −114 package_CA.xml
  46. +0 −122 package_CH.xml
  47. +0 −94 package_CreditCard.xml
  48. +0 −77 package_DE.xml
  49. +0 −87 package_DK.xml
  50. +0 −124 package_ES.xml
  51. +0 −156 package_FI.xml
  52. +0 −129 package_FR.xml
  53. +0 −178 package_Finance.xml
  54. +0 −121 package_IE.xml
  55. +0 −58 package_IR.xml
  56. +0 −126 package_ISPN.xml
  57. +0 −53 package_IT.xml
  58. +0 −81 package_LI.xml
  59. +0 −81 package_LU.xml
  60. +0 −79 package_LV.xml
  61. +0 −81 package_NO.xml
  62. +0 −63 package_NZ.xml
  63. +0 −81 package_SE.xml
  64. +0 −130 package_UK.xml
  65. +0 −119 package_US.xml
  66. +0 −88 package_esMX.xml
  67. +0 −156 package_ptBR.xml
  68. +0 −312 tests/Validate_NZ.phpt
  69. +0 −14 tests/bug11592.phpt
  70. +0 −11 tests/bug12279.phpt
  71. +0 −11 tests/bug13633.phpt
  72. +0 −10 tests/bug14075.phpt
  73. +0 −43 tests/bug14535.phpt
  74. +0 −24 tests/bug17279.phpt
  75. +0 −19 tests/bug7038.phpt
  76. +0 −23 tests/bug7176.phpt
  77. +0 −13 tests/bug7531.phpt
  78. +0 −26 tests/bug7648.phpt
  79. +0 −17 tests/bug8073.phpt
  80. +0 −11 tests/bug8629.phpt
  81. +0 −13 tests/bug8851.phpt
  82. +0 −11 tests/bug8853.phpt
  83. +0 −214 tests/credit_card.phpt
  84. +0 −166 tests/email.phpt
  85. +0 −49 tests/email_domaincheck.phpt
  86. +0 −60 tests/multicard.phpt
  87. +0 −53 tests/multiple.phpt
  88. +0 −52 tests/number.phpt
  89. +0 −252 tests/product_numbers.phpt
  90. BIN  tests/ptBR.phpt
  91. +0 −39 tests/rfc822nok.phpt
  92. +0 −63 tests/rfc822ok.phpt
  93. +0 −98 tests/testdate.phpt
  94. +0 −55 tests/testdate_minmax.phpt
  95. +0 −87 tests/uri.phpt
  96. +0 −48 tests/uri_domaincheck.phpt
  97. +0 −120 tests/validate_AT.phpt
  98. +0 −58 tests/validate_BE_bank_codes.phpt
  99. +0 −53 tests/validate_BE_bank_transfer_message.phpt
  100. +0 −33 tests/validate_BE_functions.inc.php
  101. +0 −44 tests/validate_BE_national_id.phpt
  102. +0 −96 tests/validate_BE_phone_numbers.phpt
  103. +0 −65 tests/validate_BE_post_code.phpt
  104. +0 −65 tests/validate_BE_post_code_strong.phpt
  105. +0 −55 tests/validate_BE_ssn.phpt
  106. +0 −49 tests/validate_BE_vat.phpt
  107. +0 −491 tests/validate_CA.phpt
  108. +0 −74 tests/validate_CH.phpt
  109. +0 −56 tests/validate_DE.phpt
  110. +0 −110 tests/validate_DK.phpt
  111. +0 −45 tests/validate_ES_ccc.phpt
  112. +0 −105 tests/validate_ES_cif.phpt
  113. +0 −53 tests/validate_ES_dni.phpt
  114. +0 −45 tests/validate_ES_postalCode.phpt
  115. +0 −59 tests/validate_ES_ssn.phpt
  116. +0 −49 tests/validate_FI_bankAccount.phpt
  117. +0 −63 tests/validate_FI_bikeLicensePlate.phpt
  118. +0 −47 tests/validate_FI_businessId.phpt
  119. +0 −87 tests/validate_FI_carLicensePlate.phpt
  120. +0 −54 tests/validate_FI_creditCard.phpt
  121. +0 −41 tests/validate_FI_finuid.phpt
  122. +0 −47 tests/validate_FI_partyId.phpt
  123. +0 −55 tests/validate_FI_phoneNumber.phpt
  124. +0 −73 tests/validate_FI_pin.phpt
  125. +0 −69 tests/validate_FI_postalCode.phpt
  126. +0 −49 tests/validate_FI_refNum.phpt
  127. +0 −47 tests/validate_FI_vatNumber.phpt
  128. +0 −169 tests/validate_Finance.phpt
  129. +0 −50 tests/validate_IE_IBAN.phpt
  130. +0 −51 tests/validate_IE_bankAC.phpt
  131. +0 −33 tests/validate_IE_drive.phpt
  132. +0 −50 tests/validate_IE_licensePlate.phpt
  133. +0 −35 tests/validate_IE_passport.phpt
  134. +0 −57 tests/validate_IE_phoneNumber.phpt
  135. +0 −41 tests/validate_IE_post_code.phpt
  136. +0 −38 tests/validate_IE_ppsn.phpt
  137. +0 −37 tests/validate_IE_swift.phpt
  138. +0 −48 tests/validate_IE_vatNumber.phpt
  139. +0 −70 tests/validate_IN_region.phpt
  140. +0 −48 tests/validate_IR_alphaNumeric.phpt
  141. +0 −44 tests/validate_IR_creditCard.phpt
  142. +0 −60 tests/validate_IR_mobileNumber.phpt
  143. +0 −42 tests/validate_IR_numeric.phpt
  144. +0 −80 tests/validate_IR_phoneNumber.phpt
  145. +0 −40 tests/validate_IR_postalCode.phpt
  146. +0 −50 tests/validate_IR_ssn.phpt
  147. +0 −32 tests/validate_ISIN.phpt
  148. +0 −59 tests/validate_LI_postalcodes.phpt
  149. +0 −37 tests/validate_LU_postalcodes.phpt
  150. +0 −37 tests/validate_NO_postalcodes.phpt
  151. +0 −37 tests/validate_SE_counties.phpt
  152. +0 −43 tests/validate_SE_postalcodes.phpt
  153. +0 −238 tests/validate_UK.phpt
  154. +0 −328 tests/validate_US.phpt
  155. +0 −157 tests/validate_esMX.phpt
  156. +0 −42 tests/validate_functions.inc
View
34 README.ADD_LOCALE
@@ -1,34 +0,0 @@
-If you like to add Validate subpackages for a country or
-some specific (like Finance) needs, please send a mail
-to the pear-dev Mailing list to discuss it.
-
-There is no need to create a proposal. There is no vote
-or other community requests to add a locale to validate.
-
-We do not have many requirements, but the following must
-be fullfilled:
-
-- Validate API compliant
-- No conflict with existing sub packages
-- If possible more than one maintainer (asking other
- validate_xx maintainers help)
-- PEAR CS
-
-Only the current active leads of Validate can agree or
-not to publish a subpackage (actually pajoye, dufuz).
-
-If you need an starting point then take a look at Example_Locale.php in
-the docs dir (http://cvs.php.net/pear/Validate/docs/)
-You can take that file to have something to start from and also to have
-three functions to start implementing before doing your first release.
-
-To make things even easier then you just go in there and replace [Your Name]
-with your real name <example@example.org> with your email (but still keeping
-the <> around the email) and [LocaleName] should be replaced with your locale
-name, like say HU or IS or such.
-
-Now you just have to implement those functions and write further info for each
-function where relevant (some countries have more requirements than others
-and the end developer has to know those things, urls to those infos are also fine)
-and if you have any extra functions in mind then just go and implement
-those also! ;)
View
11 TODO
@@ -1,11 +0,0 @@
-Date:
-Create warnings for ambiguous date format with %j, or %n (currently test 5,6 and 7 failed)
-Adding 'r' format (RFC 822)
-
-More Countries support
-Mail on peardev if you are interested to add validations for your area
-
-Update banks SWIFT or IBANN validation for each country (when possible)
-
-Check that for the postal codes:
-http://www.magma.ca/~djcl/postcd.txt
View
1,149 Validate.php
@@ -1,1149 +0,0 @@
-<?php
-/**
- * Validation class
- *
- * Copyright (c) 1997-2006 Pierre-Alain Joye,Tomas V.V.Cox, Amir Saied
- *
- * This source file is subject to the New BSD license, That is bundled
- * with this package in the file LICENSE, and is available through
- * the world-wide-web at
- * http://www.opensource.org/licenses/bsd-license.php
- * If you did not receive a copy of the new BSDlicense and are unable
- * to obtain it through the world-wide-web, please send a note to
- * pajoye@php.net so we can mail you a copy immediately.
- *
- * Author: Tomas V.V.Cox <cox@idecnet.com>
- * Pierre-Alain Joye <pajoye@php.net>
- * Amir Mohammad Saied <amir@php.net>
- *
- *
- * Package to validate various datas. It includes :
- * - numbers (min/max, decimal or not)
- * - email (syntax, domain check)
- * - string (predifined type alpha upper and/or lowercase, numeric,...)
- * - date (min, max, rfc822 compliant)
- * - uri (RFC2396)
- * - possibility valid multiple data with a single method call (::multiple)
- *
- * @category Validate
- * @package Validate
- * @author Tomas V.V.Cox <cox@idecnet.com>
- * @author Pierre-Alain Joye <pajoye@php.net>
- * @author Amir Mohammad Saied <amir@php.net>
- * @copyright 1997-2006 Pierre-Alain Joye,Tomas V.V.Cox,Amir Mohammad Saied
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id$
- * @link http://pear.php.net/package/Validate
- */
-
-// {{{ Constants
-/**
- * Methods for common data validations
- */
-define('VALIDATE_NUM', '0-9');
-define('VALIDATE_SPACE', '\s');
-define('VALIDATE_ALPHA_LOWER', 'a-z');
-define('VALIDATE_ALPHA_UPPER', 'A-Z');
-define('VALIDATE_ALPHA', VALIDATE_ALPHA_LOWER . VALIDATE_ALPHA_UPPER);
-define('VALIDATE_EALPHA_LOWER', VALIDATE_ALPHA_LOWER . 'áéíóúýàèìòùäëïöüÿâêîôûãñõ¨åæç½ðøþß');
-define('VALIDATE_EALPHA_UPPER', VALIDATE_ALPHA_UPPER . 'ÁÉÍÓÚÝÀÈÌÒÙÄËÏÖܾÂÊÎÔÛÃÑÕ¦ÅÆǼÐØÞ');
-define('VALIDATE_EALPHA', VALIDATE_EALPHA_LOWER . VALIDATE_EALPHA_UPPER);
-define('VALIDATE_PUNCTUATION', VALIDATE_SPACE . '\.,;\:&"\'\?\!\(\)');
-define('VALIDATE_NAME', VALIDATE_EALPHA . VALIDATE_SPACE . "'" . '\-');
-define('VALIDATE_STREET', VALIDATE_NUM . VALIDATE_NAME . "/\\ºª\.");
-
-define('VALIDATE_ITLD_EMAILS', 1);
-define('VALIDATE_GTLD_EMAILS', 2);
-define('VALIDATE_CCTLD_EMAILS', 4);
-define('VALIDATE_ALL_EMAILS', 8);
-// }}}
-
-/**
- * Validation class
- *
- * Package to validate various datas. It includes :
- * - numbers (min/max, decimal or not)
- * - email (syntax, domain check)
- * - string (predifined type alpha upper and/or lowercase, numeric,...)
- * - date (min, max)
- * - uri (RFC2396)
- * - possibility valid multiple data with a single method call (::multiple)
- *
- * @category Validate
- * @package Validate
- * @author Tomas V.V.Cox <cox@idecnet.com>
- * @author Pierre-Alain Joye <pajoye@php.net>
- * @author Amir Mohammad Saied <amir@php.net>
- * @copyright 1997-2006 Pierre-Alain Joye,Tomas V.V.Cox,Amir Mohammad Saied
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: @package_version@
- * @link http://pear.php.net/package/Validate
- */
-class Validate
-{
- // {{{ International, Generic and Country code TLDs
- /**
- * International Top-Level Domain
- *
- * This is an array of the known international
- * top-level domain names.
- *
- * @access protected
- * @var array $_iTld (International top-level domains)
- */
- var $_itld = array(
- 'arpa',
- 'root',
- );
-
- /**
- * Generic top-level domain
- *
- * This is an array of the official
- * generic top-level domains.
- *
- * @access protected
- * @var array $_gTld (Generic top-level domains)
- */
- var $_gtld = array(
- 'aero',
- 'biz',
- 'cat',
- 'com',
- 'coop',
- 'edu',
- 'gov',
- 'info',
- 'int',
- 'jobs',
- 'mil',
- 'mobi',
- 'museum',
- 'name',
- 'net',
- 'org',
- 'pro',
- 'travel',
- 'asia',
- 'post',
- 'tel',
- 'geo',
- );
-
- /**
- * Country code top-level domains
- *
- * This is an array of the official country
- * codes top-level domains
- *
- * @access protected
- * @var array $_ccTld (Country Code Top-Level Domain)
- */
- var $_cctld = array(
- 'ac',
- 'ad','ae','af','ag',
- 'ai','al','am','an',
- 'ao','aq','ar','as',
- 'at','au','aw','ax',
- 'az','ba','bb','bd',
- 'be','bf','bg','bh',
- 'bi','bj','bm','bn',
- 'bo','br','bs','bt',
- 'bu','bv','bw','by',
- 'bz','ca','cc','cd',
- 'cf','cg','ch','ci',
- 'ck','cl','cm','cn',
- 'co','cr','cs','cu',
- 'cv','cx','cy','cz',
- 'de','dj','dk','dm',
- 'do','dz','ec','ee',
- 'eg','eh','er','es',
- 'et','eu','fi','fj',
- 'fk','fm','fo','fr',
- 'ga','gb','gd','ge',
- 'gf','gg','gh','gi',
- 'gl','gm','gn','gp',
- 'gq','gr','gs','gt',
- 'gu','gw','gy','hk',
- 'hm','hn','hr','ht',
- 'hu','id','ie','il',
- 'im','in','io','iq',
- 'ir','is','it','je',
- 'jm','jo','jp','ke',
- 'kg','kh','ki','km',
- 'kn','kp','kr','kw',
- 'ky','kz','la','lb',
- 'lc','li','lk','lr',
- 'ls','lt','lu','lv',
- 'ly','ma','mc','md',
- 'me','mg','mh','mk',
- 'ml','mm','mn','mo',
- 'mp','mq','mr','ms',
- 'mt','mu','mv','mw',
- 'mx','my','mz','na',
- 'nc','ne','nf','ng',
- 'ni','nl','no','np',
- 'nr','nu','nz','om',
- 'pa','pe','pf','pg',
- 'ph','pk','pl','pm',
- 'pn','pr','ps','pt',
- 'pw','py','qa','re',
- 'ro','rs','ru','rw',
- 'sa','sb','sc','sd',
- 'se','sg','sh','si',
- 'sj','sk','sl','sm',
- 'sn','so','sr','st',
- 'su','sv','sy','sz',
- 'tc','td','tf','tg',
- 'th','tj','tk','tl',
- 'tm','tn','to','tp',
- 'tr','tt','tv','tw',
- 'tz','ua','ug','uk',
- 'us','uy','uz','va',
- 'vc','ve','vg','vi',
- 'vn','vu','wf','ws',
- 'ye','yt','yu','za',
- 'zm','zw',
- );
- // }}}
-
- /**
- * Validate a tag URI (RFC4151)
- *
- * @param string $uri tag URI to validate
- *
- * @return boolean true if valid tag URI, false if not
- *
- * @access private
- */
- function __uriRFC4151($uri)
- {
- $datevalid = false;
- if (preg_match(
- '/^tag:(?<name>.*),(?<date>\d{4}-?\d{0,2}-?\d{0,2}):(?<specific>.*)(.*:)*$/', $uri, $matches)) {
- $date = $matches['date'];
- $date6 = strtotime($date);
- if ((strlen($date) == 4) && $date <= date('Y')) {
- $datevalid = true;
- } elseif ((strlen($date) == 7) && ($date6 < strtotime("now"))) {
- $datevalid = true;
- } elseif ((strlen($date) == 10) && ($date6 < strtotime("now"))) {
- $datevalid = true;
- }
- if (self::email($matches['name'])) {
- $namevalid = true;
- } else {
- $namevalid = self::email('info@' . $matches['name']);
- }
- return $datevalid && $namevalid;
- } else {
- return false;
- }
- }
-
- /**
- * Validate a number
- *
- * @param string $number Number to validate
- * @param array $options array where:
- * 'decimal' is the decimal char or false when decimal
- * not allowed.
- * i.e. ',.' to allow both ',' and '.'
- * 'dec_prec' Number of allowed decimals
- * 'min' minimum value
- * 'max' maximum value
- *
- * @return boolean true if valid number, false if not
- *
- * @access public
- */
- function number($number, $options = array())
- {
- $decimal = $dec_prec = $min = $max = null;
- if (is_array($options)) {
- extract($options);
- }
-
- $dec_prec = $dec_prec ? "{1,$dec_prec}" : '+';
- $dec_regex = $decimal ? "[$decimal][0-9]$dec_prec" : '';
-
- if (!preg_match("|^[-+]?\s*[0-9]+($dec_regex)?\$|", $number)) {
- return false;
- }
-
- if ($decimal != '.') {
- $number = strtr($number, $decimal, '.');
- }
-
- $number = (float)str_replace(' ', '', $number);
- if ($min !== null && $min > $number) {
- return false;
- }
-
- if ($max !== null && $max < $number) {
- return false;
- }
- return true;
- }
-
- /**
- * Converting a string to UTF-7 (RFC 2152)
- *
- * @param string $string string to be converted
- *
- * @return string converted string
- *
- * @access private
- */
- function __stringToUtf7($string)
- {
- $return = '';
- $utf7 = array(
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
- 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
- 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
- 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
- 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2',
- '3', '4', '5', '6', '7', '8', '9', '+', ','
- );
-
-
- $state = 0;
-
- if (!empty($string)) {
- $i = 0;
- while ($i <= strlen($string)) {
- $char = substr($string, $i, 1);
- if ($state == 0) {
- if ((ord($char) >= 0x7F) || (ord($char) <= 0x1F)) {
- if ($char) {
- $return .= '&';
- }
- $state = 1;
- } elseif ($char == '&') {
- $return .= '&-';
- } else {
- $return .= $char;
- }
- } elseif (($i == strlen($string) ||
- !((ord($char) >= 0x7F)) || (ord($char) <= 0x1F))) {
- if ($state != 1) {
- if (ord($char) > 64) {
- $return .= '';
- } else {
- $return .= $utf7[ord($char)];
- }
- }
- $return .= '-';
- $state = 0;
- } else {
- switch($state) {
- case 1:
- $return .= $utf7[ord($char) >> 2];
- $residue = (ord($char) & 0x03) << 4;
- $state = 2;
- break;
- case 2:
- $return .= $utf7[$residue | (ord($char) >> 4)];
- $residue = (ord($char) & 0x0F) << 2;
- $state = 3;
- break;
- case 3:
- $return .= $utf7[$residue | (ord($char) >> 6)];
- $return .= $utf7[ord($char) & 0x3F];
- $state = 1;
- break;
- }
- }
- $i++;
- }
- return $return;
- }
- return '';
- }
-
- /**
- * Validate an email according to full RFC822 (inclusive human readable part)
- *
- * @param string $email email to validate,
- * will return the address for optional dns validation
- * @param array $options email() options
- *
- * @return boolean true if valid email, false if not
- *
- * @access private
- */
- function __emailRFC822(&$email, &$options)
- {
- static $address = null;
- static $uncomment = null;
- if (!$address) {
- // atom = 1*<any CHAR except specials, SPACE and CTLs>
- $atom = '[^][()<>@,;:\\".\s\000-\037\177-\377]+\s*';
- // qtext = <any CHAR excepting <">, ; => may be folded
- // "\" & CR, and including linear-white-space>
- $qtext = '[^"\\\\\r]';
- // quoted-pair = "\" CHAR ; may quote any char
- $quoted_pair = '\\\\.';
- // quoted-string = <"> *(qtext/quoted-pair) <">; Regular qtext or
- // ; quoted chars.
- $quoted_string = '"(?:' . $qtext . '|' . $quoted_pair . ')*"\s*';
- // word = atom / quoted-string
- $word = '(?:' . $atom . '|' . $quoted_string . ')';
- // local-part = word *("." word) ; uninterpreted
- // ; case-preserved
- $local_part = $word . '(?:\.\s*' . $word . ')*';
- // dtext = <any CHAR excluding "[", ; => may be folded
- // "]", "\" & CR, & including linear-white-space>
- $dtext = '[^][\\\\\r]';
- // domain-literal = "[" *(dtext / quoted-pair) "]"
- $domain_literal = '\[(?:' . $dtext . '|' . $quoted_pair . ')*\]\s*';
- // sub-domain = domain-ref / domain-literal
- // domain-ref = atom ; symbolic reference
- $sub_domain = '(?:' . $atom . '|' . $domain_literal . ')';
- // domain = sub-domain *("." sub-domain)
- $domain = $sub_domain . '(?:\.\s*' . $sub_domain . ')*';
- // addr-spec = local-part "@" domain ; global address
- $addr_spec = $local_part . '@\s*' . $domain;
- // route = 1#("@" domain) ":" ; path-relative
- $route = '@' . $domain . '(?:,@\s*' . $domain . ')*:\s*';
- // route-addr = "<" [route] addr-spec ">"
- $route_addr = '<\s*(?:' . $route . ')?' . $addr_spec . '>\s*';
- // phrase = 1*word ; Sequence of words
- $phrase = $word . '+';
- // mailbox = addr-spec ; simple address
- // / phrase route-addr ; name & addr-spec
- $mailbox = '(?:' . $addr_spec . '|' . $phrase . $route_addr . ')';
- // group = phrase ":" [#mailbox] ";"
- $group = $phrase . ':\s*(?:' . $mailbox . '(?:,\s*' . $mailbox . ')*)?;\s*';
- // address = mailbox ; one addressee
- // / group ; named list
- $address = '/^\s*(?:' . $mailbox . '|' . $group . ')$/';
-
- $uncomment =
- '/((?:(?:\\\\"|[^("])*(?:' . $quoted_string .
- ')?)*)((?<!\\\\)\((?:(?2)|.)*?(?<!\\\\)\))/';
- }
- // strip comments
- $email = preg_replace($uncomment, '$1 ', $email);
- return preg_match($address, $email);
- }
-
- /**
- * Full TLD Validation function
- *
- * This function is used to make a much more proficient validation
- * against all types of official domain names.
- *
- * @param string $email The email address to check.
- * @param array $options The options for validation
- *
- * @access protected
- *
- * @return bool True if validating succeeds
- */
- function _fullTLDValidation($email, $options)
- {
- $validate = array();
- if(!empty($options["VALIDATE_ITLD_EMAILS"])) array_push($validate, 'itld');
- if(!empty($options["VALIDATE_GTLD_EMAILS"])) array_push($validate, 'gtld');
- if(!empty($options["VALIDATE_CCTLD_EMAILS"])) array_push($validate, 'cctld');
-
- if (count($validate) === 0) {
- array_push($validate, 'itld', 'gtld', 'cctld');
- }
-
- $self = new Validate;
-
- $toValidate = array();
-
- foreach ($validate as $valid) {
- $tmpVar = '_' . (string)$valid;
-
- $toValidate[$valid] = $self->{$tmpVar};
- }
-
- $e = $self->executeFullEmailValidation($email, $toValidate);
-
- return $e;
- }
-
- /**
- * Execute the validation
- *
- * This function will execute the full email vs tld
- * validation using an array of tlds passed to it.
- *
- * @param string $email The email to validate.
- * @param array $arrayOfTLDs The array of the TLDs to validate
- *
- * @access public
- *
- * @return true or false (Depending on if it validates or if it does not)
- */
- function executeFullEmailValidation($email, $arrayOfTLDs)
- {
- $emailEnding = explode('.', $email);
- $emailEnding = $emailEnding[count($emailEnding)-1];
- foreach ($arrayOfTLDs as $validator => $keys) {
- if (in_array($emailEnding, $keys)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Validate an email
- *
- * @param string $email email to validate
- * @param mixed boolean (BC) $check_domain Check or not if the domain exists
- * array $options associative array of options
- * 'check_domain' boolean Check or not if the domain exists
- * 'use_rfc822' boolean Apply the full RFC822 grammar
- *
- * Ex.
- * $options = array(
- * 'check_domain' => 'true',
- * 'fullTLDValidation' => 'true',
- * 'use_rfc822' => 'true',
- * 'VALIDATE_GTLD_EMAILS' => 'true',
- * 'VALIDATE_CCTLD_EMAILS' => 'true',
- * 'VALIDATE_ITLD_EMAILS' => 'true',
- * );
- *
- * @return boolean true if valid email, false if not
- *
- * @access public
- */
- function email($email, $options = null)
- {
- $check_domain = false;
- $use_rfc822 = false;
- if (is_bool($options)) {
- $check_domain = $options;
- } elseif (is_array($options)) {
- extract($options);
- }
-
- /**
- * Check for IDN usage so we can encode the domain as Punycode
- * before continuing.
- */
- $hasIDNA = false;
-
- if (Validate::_includePathFileExists('Net/IDNA.php')) {
- include_once('Net/IDNA.php');
- $hasIDNA = true;
- }
-
- if ($hasIDNA === true) {
- if (strpos($email, '@') !== false) {
- $tmpEmail = explode('@', $email);
- $domain = array_pop($tmpEmail);
-
- // Check if the domain contains characters > 127 which means
- // it's an idn domain name.
- $chars = count_chars($domain, 1);
- if (!empty($chars) && max(array_keys($chars)) > 127) {
- $idna =& Net_IDNA::singleton();
- $domain = $idna->encode($domain);
- }
-
- array_push($tmpEmail, $domain);
- $email = implode('@', $tmpEmail);
- }
- }
-
- /**
- * @todo Fix bug here.. even if it passes this, it won't be passing
- * The regular expression below
- */
- if (isset($fullTLDValidation)) {
- //$valid = Validate::_fullTLDValidation($email, $fullTLDValidation);
- $valid = Validate::_fullTLDValidation($email, $options);
-
- if (!$valid) {
- return false;
- }
- }
-
- // the base regexp for address
- $regex = '&^(?: # recipient:
- ("\s*(?:[^"\f\n\r\t\v\b\s]+\s*)+")| #1 quoted name
- ([-\w!\#\$%\&\'*+~/^`|{}]+(?:\.[-\w!\#\$%\&\'*+~/^`|{}]+)*)) #2 OR dot-atom
- @(((\[)? #3 domain, 4 as IPv4, 5 optionally bracketed
- (?:(?:(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:[0-1]?[0-9]?[0-9]))\.){3}
- (?:(?:25[0-5])|(?:2[0-4][0-9])|(?:[0-1]?[0-9]?[0-9]))))(?(5)\])|
- ((?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)*[a-z0-9](?:[-a-z0-9]*[a-z0-9])?) #6 domain as hostname
- \.((?:([^- ])[-a-z]*[-a-z]))) #7 TLD
- $&xi';
-
- //checks if exists the domain (MX or A)
- if ($use_rfc822? Validate::__emailRFC822($email, $options) :
- preg_match($regex, $email)) {
- if ($check_domain && function_exists('checkdnsrr')) {
- $domain = preg_replace('/[^-a-z.0-9]/i', '', array_pop(explode('@', $email)));
- if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) {
- return true;
- }
- return false;
- }
- return true;
- }
- return false;
- }
-
- /**
- * Validate a string using the given format 'format'
- *
- * @param string $string String to validate
- * @param array $options Options array where:
- * 'format' is the format of the string
- * Ex:VALIDATE_NUM . VALIDATE_ALPHA (see constants)
- * 'min_length' minimum length
- * 'max_length' maximum length
- *
- * @return boolean true if valid string, false if not
- *
- * @access public
- */
- function string($string, $options)
- {
- $format = null;
- $min_length = 0;
- $max_length = 0;
-
- if (is_array($options)) {
- extract($options);
- }
-
- if ($format && !preg_match("|^[$format]*\$|s", $string)) {
- return false;
- }
-
- if ($min_length && strlen($string) < $min_length) {
- return false;
- }
-
- if ($max_length && strlen($string) > $max_length) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Validate an URI (RFC2396)
- * This function will validate 'foobarstring' by default, to get it to validate
- * only http, https, ftp and such you have to pass it in the allowed_schemes
- * option, like this:
- * <code>
- * $options = array('allowed_schemes' => array('http', 'https', 'ftp'))
- * var_dump(Validate::uri('http://www.example.org', $options));
- * </code>
- *
- * NOTE 1: The rfc2396 normally allows middle '-' in the top domain
- * e.g. http://example.co-m should be valid
- * However, as '-' is not used in any known TLD, it is invalid
- * NOTE 2: As double shlashes // are allowed in the path part, only full URIs
- * including an authority can be valid, no relative URIs
- * the // are mandatory (optionally preceeded by the 'sheme:' )
- * NOTE 3: the full complience to rfc2396 is not achieved by default
- * the characters ';/?:@$,' will not be accepted in the query part
- * if not urlencoded, refer to the option "strict'"
- *
- * @param string $url URI to validate
- * @param array $options Options used by the validation method.
- * key => type
- * 'domain_check' => boolean
- * Whether to check the DNS entry or not
- * 'allowed_schemes' => array, list of protocols
- * List of allowed schemes ('http',
- * 'ssh+svn', 'mms')
- * 'strict' => string the refused chars
- * in query and fragment parts
- * default: ';/?:@$,'
- * empty: accept all rfc2396 foreseen chars
- *
- * @return boolean true if valid uri, false if not
- *
- * @access public
- */
- function uri($url, $options = null)
- {
- $strict = ';/?:@$,';
- $domain_check = false;
- $allowed_schemes = null;
- if (is_array($options)) {
- extract($options);
- }
- if (is_array($allowed_schemes) &&
- in_array("tag", $allowed_schemes)
- ) {
- if (strpos($url, "tag:") === 0) {
- return self::__uriRFC4151($url);
- }
- }
-
- if (preg_match(
- '&^(?:([a-z][-+.a-z0-9]*):)? # 1. scheme
- (?:// # authority start
- (?:((?:%[0-9a-f]{2}|[-a-z0-9_.!~*\'();:\&=+$,])*)@)? # 2. authority-userinfo
- (?:((?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)*[a-z](?:[a-z0-9]+)?\.?) # 3. authority-hostname OR
- |([0-9]{1,3}(?:\.[0-9]{1,3}){3})) # 4. authority-ipv4
- (?::([0-9]*))?) # 5. authority-port
- ((?:/(?:%[0-9a-f]{2}|[-a-z0-9_.!~*\'():@\&=+$,;])*)*/?)? # 6. path
- (?:\?([^#]*))? # 7. query
- (?:\#((?:%[0-9a-f]{2}|[-a-z0-9_.!~*\'();/?:@\&=+$,])*))? # 8. fragment
- $&xi', $url, $matches)) {
- $scheme = isset($matches[1]) ? $matches[1] : '';
- $authority = isset($matches[3]) ? $matches[3] : '' ;
- if (is_array($allowed_schemes) &&
- !in_array($scheme, $allowed_schemes)
- ) {
- return false;
- }
- if (!empty($matches[4])) {
- $parts = explode('.', $matches[4]);
- foreach ($parts as $part) {
- if ($part > 255) {
- return false;
- }
- }
- } elseif ($domain_check && function_exists('checkdnsrr')) {
- if (!checkdnsrr($authority, 'A')) {
- return false;
- }
- }
- if ($strict) {
- $strict = '#[' . preg_quote($strict, '#') . ']#';
- if ((!empty($matches[7]) && preg_match($strict, $matches[7]))
- || (!empty($matches[8]) && preg_match($strict, $matches[8]))) {
- return false;
- }
- }
- return true;
- }
- return false;
- }
-
- /**
- * Validate date and times. Note that this method need the Date_Calc class
- *
- * @param string $date Date to validate
- * @param array $options array options where :
- * 'format' The format of the date (%d-%m-%Y)
- * or rfc822_compliant
- * 'min' The date has to be greater
- * than this array($day, $month, $year)
- * or PEAR::Date object
- * 'max' The date has to be smaller than
- * this array($day, $month, $year)
- * or PEAR::Date object
- *
- * @return boolean true if valid date/time, false if not
- *
- * @access public
- */
- function date($date, $options)
- {
- $max = false;
- $min = false;
- $format = '';
-
- if (is_array($options)) {
- extract($options);
- }
-
- if (strtolower($format) == 'rfc822_compliant') {
- $preg = '&^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),) \s+
- (?:(\d{2})?) \s+
- (?:(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)?) \s+
- (?:(\d{2}(\d{2})?)?) \s+
- (?:(\d{2}?)):(?:(\d{2}?))(:(?:(\d{2}?)))? \s+
- (?:[+-]\d{4}|UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[A-IK-Za-ik-z])$&xi';
-
- if (!preg_match($preg, $date, $matches)) {
- return false;
- }
-
- $year = (int)$matches[4];
- $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
- 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
- $month = array_keys($months, $matches[3]);
- $month = (int)$month[0]+1;
- $day = (int)$matches[2];
- $weekday = $matches[1];
- $hour = (int)$matches[6];
- $minute = (int)$matches[7];
- isset($matches[9]) ? $second = (int)$matches[9] : $second = 0;
-
- if ((strlen($year) != 4) ||
- ($day > 31 || $day < 1)||
- ($hour > 23) ||
- ($minute > 59) ||
- ($second > 59)) {
- return false;
- }
- } else {
- $date_len = strlen($format);
- for ($i = 0; $i < $date_len; $i++) {
- $c = $format{$i};
- if ($c == '%') {
- $next = $format{$i + 1};
- switch ($next) {
- case 'j':
- case 'd':
- if ($next == 'j') {
- $day = (int)Validate::_substr($date, 1, 2);
- } else {
- $day = (int)Validate::_substr($date, 0, 2);
- }
- if ($day < 1 || $day > 31) {
- return false;
- }
- break;
- case 'm':
- case 'n':
- if ($next == 'm') {
- $month = (int)Validate::_substr($date, 0, 2);
- } else {
- $month = (int)Validate::_substr($date, 1, 2);
- }
- if ($month < 1 || $month > 12) {
- return false;
- }
- break;
- case 'Y':
- case 'y':
- if ($next == 'Y') {
- $year = Validate::_substr($date, 4);
- $year = (int)$year?$year:'';
- } else {
- $year = (int)(substr(date('Y'), 0, 2) .
- Validate::_substr($date, 2));
- }
- if (strlen($year) != 4 || $year < 0 || $year > 9999) {
- return false;
- }
- break;
- case 'g':
- case 'h':
- if ($next == 'g') {
- $hour = Validate::_substr($date, 1, 2);
- } else {
- $hour = Validate::_substr($date, 2);
- }
- if (!preg_match('/^\d+$/', $hour) || $hour < 0 || $hour > 12) {
- return false;
- }
- break;
- case 'G':
- case 'H':
- if ($next == 'G') {
- $hour = Validate::_substr($date, 1, 2);
- } else {
- $hour = Validate::_substr($date, 2);
- }
- if (!preg_match('/^\d+$/', $hour) || $hour < 0 || $hour > 24) {
- return false;
- }
- break;
- case 's':
- case 'i':
- $t = Validate::_substr($date, 2);
- if (!preg_match('/^\d+$/', $t) || $t < 0 || $t > 59) {
- return false;
- }
- break;
- default:
- trigger_error("Not supported char `$next' after % in offset " . ($i+2), E_USER_WARNING);
- }
- $i++;
- } else {
- //literal
- if (Validate::_substr($date, 1) != $c) {
- return false;
- }
- }
- }
- }
- // there is remaing data, we don't want it
- if (strlen($date) && (strtolower($format) != 'rfc822_compliant')) {
- return false;
- }
-
- if (isset($day) && isset($month) && isset($year)) {
- if (!checkdate($month, $day, $year)) {
- return false;
- }
-
- if (strtolower($format) == 'rfc822_compliant') {
- if ($weekday != date("D", mktime(0, 0, 0, $month, $day, $year))) {
- return false;
- }
- }
-
- if ($min) {
- include_once 'Date/Calc.php';
- if (is_a($min, 'Date') &&
- (Date_Calc::compareDates($day, $month, $year,
- $min->getDay(), $min->getMonth(), $min->getYear()) < 0)
- ) {
- return false;
- } elseif (is_array($min) &&
- (Date_Calc::compareDates($day, $month, $year,
- $min[0], $min[1], $min[2]) < 0)
- ) {
- return false;
- }
- }
-
- if ($max) {
- include_once 'Date/Calc.php';
- if (is_a($max, 'Date') &&
- (Date_Calc::compareDates($day, $month, $year,
- $max->getDay(), $max->getMonth(), $max->getYear()) > 0)
- ) {
- return false;
- } elseif (is_array($max) &&
- (Date_Calc::compareDates($day, $month, $year,
- $max[0], $max[1], $max[2]) > 0)
- ) {
- return false;
- }
- }
- }
-
- return true;
- }
-
- /**
- * Substr
- *
- * @param string &$date Date
- * @param string $num Length
- * @param string $opt Unknown
- *
- * @access private
- * @return string
- */
- function _substr(&$date, $num, $opt = false)
- {
- if ($opt && strlen($date) >= $opt && preg_match('/^[0-9]{'.$opt.'}/', $date, $m)) {
- $ret = $m[0];
- } else {
- $ret = substr($date, 0, $num);
- }
- $date = substr($date, strlen($ret));
- return $ret;
- }
-
- function _modf($val, $div)
- {
- if (function_exists('bcmod')) {
- return bcmod($val, $div);
- } elseif (function_exists('fmod')) {
- return fmod($val, $div);
- }
- $r = $val / $div;
- $i = intval($r);
- return intval($val - $i * $div + .1);
- }
-
- /**
- * Calculates sum of product of number digits with weights
- *
- * @param string $number number string
- * @param array $weights reference to array of weights
- *
- * @access protected
- *
- * @return int returns product of number digits with weights
- */
- function _multWeights($number, &$weights)
- {
- if (!is_array($weights)) {
- return -1;
- }
- $sum = 0;
-
- $count = min(count($weights), strlen($number));
- if ($count == 0) { // empty string or weights array
- return -1;
- }
- for ($i = 0; $i < $count; ++$i) {
- $sum += intval(substr($number, $i, 1)) * $weights[$i];
- }
-
- return $sum;
- }
-
- /**
- * Calculates control digit for a given number
- *
- * @param string $number number string
- * @param array $weights reference to array of weights
- * @param int $modulo (optionsl) number
- * @param int $subtract (optional) number
- * @param bool $allow_high (optional) true if function can return number higher than 10
- *
- * @access protected
- *
- * @return int -1 calculated control number is returned
- */
- function _getControlNumber($number, &$weights, $modulo = 10, $subtract = 0, $allow_high = false)
- {
- // calc sum
- $sum = Validate::_multWeights($number, $weights);
- if ($sum == -1) {
- return -1;
- }
- $mod = Validate::_modf($sum, $modulo); // calculate control digit
-
- if ($subtract > $mod && $mod > 0) {
- $mod = $subtract - $mod;
- }
- if ($allow_high === false) {
- $mod %= 10; // change 10 to zero
- }
- return $mod;
- }
-
- /**
- * Validates a number
- *
- * @param string $number number to validate
- * @param array $weights reference to array of weights
- * @param int $modulo (optional) number
- * @param int $subtract (optional) number
- *
- * @access protected
- *
- * @return bool true if valid, false if not
- */
- function _checkControlNumber($number, &$weights, $modulo = 10, $subtract = 0)
- {
- if (strlen($number) < count($weights)) {
- return false;
- }
- $target_digit = substr($number, count($weights), 1);
- $control_digit = Validate::_getControlNumber($number, $weights, $modulo, $subtract, $modulo > 10);
-
- if ($control_digit == -1) {
- return false;
- }
- if ($target_digit === 'X' && $control_digit == 10) {
- return true;
- }
- if ($control_digit != $target_digit) {
- return false;
- }
- return true;
- }
-
- /**
- * Bulk data validation for data introduced in the form of an
- * assoc array in the form $var_name => $value.
- * Can be used on any of Validate subpackages
- *
- * @param array $data Ex: array('name' => 'toto', 'email' => 'toto@thing.info');
- * @param array $val_type Contains the validation type and all parameters used in.
- * 'val_type' is not optional
- * others validations properties must have the same name as the function
- * parameters.
- * Ex: array('toto'=>array('type'=>'string','format'='toto@thing.info','min_length'=>5));
- * @param boolean $remove if set, the elements not listed in data will be removed
- *
- * @return array value name => true|false the value name comes from the data key
- *
- * @access public
- */
- function multiple(&$data, &$val_type, $remove = false)
- {
- $keys = array_keys($data);
- $valid = array();
-
- foreach ($keys as $var_name) {
- if (!isset($val_type[$var_name])) {
- if ($remove) {
- unset($data[$var_name]);
- }
- continue;
- }
- $opt = $val_type[$var_name];
- $methods = get_class_methods('Validate');
- $val2check = $data[$var_name];
- // core validation method
- if (in_array(strtolower($opt['type']), $methods)) {
- //$opt[$opt['type']] = $data[$var_name];
- $method = $opt['type'];
- unset($opt['type']);
-
- if (sizeof($opt) == 1 && is_array(reset($opt))) {
- $opt = array_pop($opt);
- }
- $valid[$var_name] = call_user_func(array('Validate', $method), $val2check, $opt);
-
- /**
- * external validation method in the form:
- * "<class name><underscore><method name>"
- * Ex: us_ssn will include class Validate/US.php and call method ssn()
- */
- } elseif (strpos($opt['type'], '_') !== false) {
- $validateType = explode('_', $opt['type']);
- $method = array_pop($validateType);
- $class = implode('_', $validateType);
- $classPath = str_replace('_', DIRECTORY_SEPARATOR, $class);
- $class = 'Validate_' . $class;
- if (Validate::_includePathFileExists("Validate/$classPath.php")) {
- include_once "Validate/$classPath.php";
- } else {
- trigger_error("$class isn't installed or you may have some permission issues", E_USER_ERROR);
- }
-
- $ce = substr(phpversion(), 0, 1) > 4 ?
- class_exists($class, false) : class_exists($class);
- if (!$ce ||
- !in_array($method, get_class_methods($class))
- ) {
- trigger_error("Invalid validation type $class::$method",
- E_USER_WARNING);
- continue;
- }
- unset($opt['type']);
- if (sizeof($opt) == 1) {
- $opt = array_pop($opt);
- }
- $valid[$var_name] = call_user_func(array($class, $method),
- $data[$var_name], $opt);
- } else {
- trigger_error("Invalid validation type {$opt['type']}",
- E_USER_WARNING);
- }
- }
- return $valid;
- }
-
- /**
- * Determine whether specified file exists along the include path.
- *
- * @param string $filename file to search for
- *
- * @access private
- *
- * @return bool true if file exists
- */
- function _includePathFileExists($filename)
- {
- $paths = explode(":", ini_get("include_path"));
- $result = false;
-
- while ((!($result)) && (list($key,$val) = each($paths))) {
- $result = file_exists($val . "/" . $filename);
- }
- return $result;
- }
-}
-
View
135 Validate/AT.php
@@ -1,135 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-/**
- * Specific validation methods for data used in Austria
- *
- * PHP Versions 4 and 5
- *
- * This source file is subject to the New BSD license, That is bundled
- * with this package in the file LICENSE, and is available through
- * the world-wide-web at
- * http://www.opensource.org/licenses/bsd-license.php
- * If you did not receive a copy of the new BSDlicense and are unable
- * to obtain it through the world-wide-web, please send a note to
- * pajoye@php.net so we can mail you a copy immediately.
- *
- * @category Validate
- * @package Validate_AT
- * @author Michael Wallner <mike@php.net>
- * @author Byron Adams <byron.adams54@gmail.com>
- * @copyright 1997-2005 Michael Wallner
- * @copyright 2006 Byron Adams
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id$
- * @link http://pear.php.net/package/Validate_AT
- */
-
-
-
-/**
- * Data validation class for Austria
- *
- * This class provides methods to validate:
- * - Social insurance number (Sozialversicherungsnummer)
- * - Postal code (Postleitzahl)
- * - Regional code (Regionaler Code)
- *
- * @category Validate
- * @package Validate_AT
- * @author Michael Wallner <mike@php.net>
- * @author Byron Adams <byron.adams54@gmail.com>
- * @copyright 1997-2005 Michael Wallner
- * @copyright 2006 Byron Adams
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: @package_version@
- * @link http://pear.php.net/package/Validate_AT
- */
-
-class Validate_AT
-{
- /**
- * Validate postcode ("Postleitzahl")
- *
- * @param string $postcode postcode to validate
- * @param bool $strong optional; strong checks against a list of postcodes
- * @param string $dataDir optional; name of directory datafile can be
- * found in. set during install process but may be
- * overridden.
- *
- * @static $postcodes
- * @access public
- * @return bool true if postcode is ok, false otherwise
- */
- function postalCode($postcode, $strong = false, $dataDir = null)
- {
- if ($strong) {
- static $postcodes;
-
- if (!isset($postcodes)) {
- $paths = array();
- if (!empty($dataDir)) {
- $paths[] = $dataDir . '/AT_postcodes.txt';
- }
- $paths[] = '@DATADIR@/Validate_AT/AT_postcodes.txt';
- $paths[] = dirname(dirname(__FILE__)) . '/data/AT_postcodes.txt';
-
- foreach ($paths as $file) {
- if (file_exists($file)) {
- $postcodes = array_map('trim', file($file));
- break;
- }
- }
- }
-
- return in_array((int)$postcode, $postcodes);
- }
- return preg_match("(^[0-9]{4}$)", $postcode);
- }
-
- /**
- * Validate SSN ("Sozialversicherungsnummer")
- *
- * @param string $ssn the SSN/SVN number to validate
- *
- * @return bool true if SVN is ok, false otherwise
- * @access public
- */
- function ssn($ssn)
- {
- $weights = array("3", "7", "9", "0", "5", "8", "4", "2", "1", "6");
-
- $lssn = preg_replace("/[^\d]/", "", trim($ssn));
- $digits = str_split($lssn);
-
- $sum = 0;
-
- foreach ($digits as $key => $digit) {
- $sum += $digit * $weights[$key];
- }
-
- return ($sum % 11 == $lssn{3});
- }
-
- /**
- * Validates Austrian Regional Code ("Regionaler Code")
- *
- * The validation is based on FIPS 10-4 region codes.
- * http://en.wikipedia.org/wiki/FIPS_10-4
- *
- * @param string $region regional code to validate
- *
- * @access public
- * @return bool true if regional code is ok, false otherwise
- * @link en.wikipedia.org/wiki/List_of_FIPS_region_codes_(A-C)#AU:_Austria
- */
- function region($region)
- {
- $region = str_ireplace(array("AU", "-", " "), "", $region);
-
- if (!ctype_digit($region)) {
- return false;
- }
-
- return ($region > 0 && $region < 10);
- }
-}
View
467 Validate/BE.php
@@ -1,467 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-/**
- * Data validation class for Belgium
- *
- * PHP Versions 4 and 5
- *
- * This source file is subject to the New BSD license, That is bundled
- * with this package in the file LICENSE, and is available through
- * the world-wide-web at
- * http://www.opensource.org/licenses/bsd-license.php
- * If you did not receive a copy of the new BSDlicense and are unable
- * to obtain it through the world-wide-web, please send a note to
- * pajoye@php.net so we can mail you a copy immediately.
- *
- * @category Validate
- * @package Validate_BE
- * @author Christophe Gesché <moosh@php.net>
- * @copyright 1997-2005 Christophe Gesché
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id$
- * @link http://pear.php.net/package/Validate_BE
- */
-require_once 'Validate.php';
-
-/**
- * @constant VALIDATE_BE_PHONENUMBER_TYPE_ANY
- * @constant VALIDATE_BE_PHONENUMBER_TYPE_NORMAL
- * @constant VALIDATE_BE_PHONENUMBER_TYPE_MOBILE
- */
-//Any belgian phonenumber
-define('VALIDATE_BE_PHONENUMBER_TYPE_ANY', 0);
-//only normal phonenumber (mobile numers are not allowed)
-define('VALIDATE_BE_PHONENUMBER_TYPE_NORMAL', 1);
-//only mobile numbers are allowed
-define('VALIDATE_BE_PHONENUMBER_TYPE_MOBILE', 2);
-define('VALIDATE_BE_BANKCODE_MODULUS', 97);
-define('VALIDATE_BE_BANK_TRANSFER_MESSAGE', 97);
-define('VALIDATE_BE_SSN_MODULUS', 97);
-define('VALIDATE_BE_VAT_MODULUS', 97);
-
-/**
- * Data validation class for Belgium
- *
- * This class provides methods to validate:
- * - Postal code
- * - Belgian bank code
- *
- * @category Validate
- * @package Validate_BE
- * @author Christophe Gesché <moosh@php.net>
- * @copyright 1997-2005 Christophe Gesché
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version Release:@packageversion@
- * @link http://pear.php.net/package/Validate_BE
- */
-class Validate_BE
-{
- /**
- * Validate a Belgian social security number
- *
- * The belgian social security number is on the SIS card of all belgian.
- *
- * A check digit is the last one, computed the standard
- * _get_control_number function.
- *
- * @param string $nationalId ssn to validate
- *
- * @static
- * @access public
- * @return bool true on success
- */
- function nationalId($nationalId)
- {
- $nationalId = strtr($nationalId, '-/\ :', '.....');
- $nationalId = str_replace('.', '', $nationalId);
- // RULE 1 : 11 digit.
- if (!(bool) preg_match('/^[0-9]{11}$/', $nationalId)) {
- return false;
- }
-
-
- // RULE 2 : ssn begin with a reversed date
- $year = substr($nationalId, 0, 2);
- $month = substr($nationalId, 2, 2);
- $day = substr($nationalId, 4, 2);
- $number = substr($nationalId, 0, 9);
- $check = substr($nationalId, 9, 2);
-
- /**
- * Check that the date is valid
- */
- if (!Validate::date("$year-$month-$day", array('format' => '%y-%m-%d'))) {
- return false;
- }
-
- // RULE 3 check is 97 - modulo 97 of all or RULES 3BIS
- if ((97 - Validate::_modf($number, VALIDATE_BE_SSN_MODULUS)) == $check) {
- return true;
- }
-
- // RULE 3 BIS
- // if RULE 3 check faild, prepend 2 to the number and retry
- if ((97 - Validate::_modf(2000000000 + $number,
- VALIDATE_BE_SSN_MODULUS)) == $check) {
- return true;
- }
-
- return false;
- }
-
- /**
- * Validate a Belgian social security number
- *
- * The belgian social security number is on the SIS card of all belgian.
- *
- * A check digit is the last one, computed the standard
- * _get_control_number function.
- *
- * @param string $ssn ssn to validate
- *
- * @access public
- * @return bool true on success
- * @static
- */
- function ssn($ssn)
- {
- // RULE 1 : 11 digit.
- if (!(bool) preg_match('/^[0-9]{11}$/', $ssn)) {
- return false;
- }
-
-
- // RULE 2 : ssn begin with a reversed date
- $year = substr($ssn, 0, 2);
- $month = substr($ssn, 2, 2);
- $day = substr($ssn, 4, 2);
- $number = substr($ssn, 0, 9);
- $check = substr($ssn, 9, 2);
-
- /**
- * Check that the date is valid
- */
- if (!Validate::date("$year-$month-$day", array('format' => '%y-%m-%d'))) {
- return false;
- }
-
- // RULE 3 check is 97 - modulo 97 of all or RULES 3BIS
- if ((97 - Validate::_modf($number, VALIDATE_BE_SSN_MODULUS)) == $check) {
- return true;
- }
-
- // RULE 3 BIS
- // if RULE 3 check faild, prepend 2 to the number and retry
- if ((97 - Validate::_modf(2000000000 + $number,
- VALIDATE_BE_SSN_MODULUS)) == $check) {
- return true;
- }
-
- return false;
- }
-
- /**
- * Validate a Belgian postcode
- *
- * @param string $postcode postcode to validate
- * @param bool $strong optional; strong checks (e.g. against a list
- * of postcodes)
- * @param string $dataDir optional; name of directory datafile can be
- * found in. set during install process but may be
- * overridden.
- *
- * @return bool true if postcode is ok, false otherwise
- */
- function postalCode($postcode, $strong = false, $dataDir = null)
- {
- static $postCodeList = null;
-
- $postcode = ltrim(ltrim(strtolower($postcode), 'b'), '-');
- if ($strong) {
- $paths = array();
- if (!empty($dataDir)) {
- $paths[] = $dataDir . '/BE_postcodes.txt';
- }
- $paths[] = '@DATADIR@/Validate_BE/BE_postcodes.txt';
- $paths[] = dirname(dirname(__FILE__)) . '/data/BE_postcodes.txt';
-
- if (!isset($postCodeList)) {
- $file = null;
- foreach ($paths as $path) {
- if (file_exists($path)) {
- $file = $path;
- }
- }
-
- if (empty($file)) {
- return false;
- }
-
- if (file_exists($file)) {
- foreach (file($file) as $line) {
- $postCodeList[] = substr($line, 0, 4);
- }
- }
- }
-
- return (bool) in_array((int) $postcode, $postCodeList);
- }
- return (bool) preg_match('/^[1-9][0-9]{3}$/', $postcode);
- }
-
- /**
- * Validate a Belgian bank account number
- *
- * Belgian bankcodes consist of
- * - 3-figure number for the bank socity
- * - 7-figure number for the account number
- * - 2-figure number for mod 97
- *
- * @param string $bankCode Belgian bankcode to validate
- *
- * @return bool true if bankcode is ok, false otherwise
- */
- function bankCode($bankCode)
- {
- if ((bool) preg_match('/^[0-9]{3}[ .\/-]?[0-9]{7}[ .\/-]?[0-9]{2}$/', $bankCode)) {
- $bankCode = str_replace(' ', '', strtr($bankCode, '/-.', ' '));
- $num = substr($bankCode, 0, 10);
- $checksum = substr($bankCode, 10, 2);
- if ($checksum == Validate::_modf($num, VALIDATE_BE_BANKCODE_MODULUS)) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
-
- /**
- * Validate a Belgian transfert message
- *
- * Belgian transfert (virement) can be done with a structured message
- * 12 figure
- * -10-figure number for the message
- * - 2-figure number for mod 97
- *
- * @param string $bankTransferMessage Belgian bankcode to validate
- *
- * @return bool true if bankcode is ok, false otherwise
- */
- function bankTransferMessage($bankTransferMessage)
- {
- if ((bool) preg_match('/^[0-9]{3}[ \.\/-]?[0-9]{4}[ \.\/-]?[0-9]{5}$/',
- $bankTransferMessage)) {
- $message = strtr($bankTransferMessage, '/-.', ' ');
-
- $bankTransferMessage = str_replace(' ', '', $message);
-
- $num = substr($bankTransferMessage, 0, 10);
- $checksum = substr($bankTransferMessage, 10, 2);
- if ($checksum == Validate::_modf($num,
- VALIDATE_BE_BANK_TRANSFER_MESSAGE)) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
-
- /**
- * Validate a VAT account number
- *
- * Belgian VAT consist of
- * - 3-figure number
- *
- * Actually no doc was found about a checksum
- *
- * @param string $vat Belgian VAT to validate
- *
- * @return bool true if VAT is ok, false otherwise
- */
- function vat($vat)
- {
- if ((bool) ( preg_match('/^[0-9]{3}[ \.\/-]?[0-9]{3}[ \.\/-]?[0-9]{3}$/',
- $vat))) {
- $vat = str_replace(' ', '', strtr($vat, '/-.', ' '));
- if (strlen($vat) == 9) {
- $number = substr($vat, 0, 7);
- $checksum = substr($vat, 7, 2);
- if (VALIDATE_BE_VAT_MODULUS - $checksum ==
- (Validate::_modf($number, VALIDATE_BE_VAT_MODULUS))) {
- return true;
- }
- }
- }
- return false;
- }
-
-
- /**
- * Validate a phonenumber
- * 065 12 34 56
- * 02 123 45 67
- * O485 12 34 56
- * 00 32 65 12 34 56
- * 00 32 2 123 45 67
- * 00 32 485 12 34 56
- * + 32 65 12 34 56
- * + 32 2 123 45 67
- * + 32 485 12 34 56
- * ++ 32 65 12 34 56
- * ++ 32 2 123 45 67
- * ++ 32 485 12 34 56
- *
- * 010 Waver
- * 011 Hasselt
- * 012 Tongeren
- * 013 Diest
- * 014 Herentals, Turnhout
- * 015 Mechelen
- * 016 Leuven, Tienen
- * 019 Borgworm (Frans: Waremme)
- * 02 Brussel
- * 03 Antwerpen
- * 04 Luik
- * 050 Brugge, Zeebrugge
- * 051 Roeselare
- * 052 Dendermonde
- * 053 Aalst
- * 054 Ninove
- * 055 Ronse
- * 056 Kortrijk, Komen-Waasten
- * 057 Ieper
- * 058 Veurne
- * 059 Oostende
- * 060 Chimay
- * 061 Libramont-Chevigny
- * 063 Aarlen
- * 064 La Louvière
- * 065 Bergen (Frans: Mons)
- * 067 Nijvel
- * 068 Ath
- * 069 Doornik
- * 071 Charleroi
- * 080 Stavelot
- * 081 Namen
- * 082 Dinant
- * 083 Ciney
- * 084 Marche-en-Famenne
- * 085 Hoei
- * 086 Durbuy
- * 087 Verviers
- * 089 Genk
- * 09 Gent
- *
- * 0472-0479 mobiel (Proximus)
- * 0485-0486 mobiel (Base)
- * 0494-0499 mobiel (Mobistar)
- *
- * 070 commercieel
- * 0800 gratis
- * 0900-0905 commercieel
- *
- * NOTE : this validate want a BELGIAN phonenumber to return true,
- * not a valid number to call FROM belgium
- *
- * @param string $phonenumber Belgian phonenumber (can be in international
- * format (eg +32 or 0032)
- * @param int $type Type of phonenumber to check / to attempt
- *
- * @return bool true if (phone) number is correct
- * @see http://roamers.proximus.be/fr/Call_In_Belgium/CIB_AZ.html
- */
- function phoneNumber($phonenumber, $type = VALIDATE_BE_PHONENUMBER_TYPE_ANY)
- {
- $zoneprefixes['littlezone'] = array ('010', '011', '012', '013', '014',
- '015', '016', '019', '050', '051',
- '052', '053', '054', '055', '056',
- '057', '058', '059', '060', '061',
- '063', '064', '065', '067', '068',
- '069', '071', '080', '081', '082',
- '083', '084', '085', '086', '087',
- '089');
- $zoneprefixes['bigzone'] = array('02', '03', '04', '09');
- $zoneprefixes['mobile'] = array('0472', '0473', '0474', '0475',
- '0476', '0477', '0478', '0479 ',
- '0485', '0486 ', '0494', '0495',
- '0496', '0497', '0498', '0499');
-
- $result = false;
- // Cleaning the phone number
- $phonenumber = trim($phonenumber);
- // international numba can begin with + or ++
- // If one, prepend a second
- if ($phonenumber[0] == '+' && $phonenumber[1] != '+') {
- $phonenumber = '+' . $phonenumber;
- }
-
- // if phone number begin by a + replace it by 0
- // replace other non numerical charater witha blancspace
- // finaly remove all blank spaces.
- $phonenumber = str_replace(' ', '', strtr($phonenumber, '+/-.', '0 '));
-
-
- // detect if it's a national or international numba
- if (substr($phonenumber, 0, 2) == '00') {
- // $is_inter = TRUE;
- // International Number
- if (!substr($phonenumber, 2, 2) == '32') {
- // international number but not with belgian prefix
- // validate::failure ('not the international prefix');
- return false;
- } else {
- $phonenumber = str_replace('0032', '0', $phonenumber);
- }
-
- }
-
- // search national prefix of numba (mobile, big zone, little zone)
- $is_mobile = (in_array(substr($phonenumber, 0, 4), $zoneprefixes['mobile']));
- if (!$is_mobile) {
- $in_bigzone = in_array(substr($phonenumber, 0, 2),
- $zoneprefixes['bigzone']);
- $in_littlezone = in_array(substr($phonenumber, 0, 3),
- $zoneprefixes['littlezone']);
- }
- // if national prefix not detected, it's a bad number
- if ( ! $is_mobile && ! $in_bigzone && ! $in_littlezone) {
- return false; // wrong prefix
- }
-
- // try to accept as Type VALIDATE_BE_PHONENUMBER_TYPE_NORMAL (not mobile)
- if ($type == VALIDATE_BE_PHONENUMBER_TYPE_ANY ||
- $type == VALIDATE_BE_PHONENUMBER_TYPE_NORMAL) {
- if (!$is_mobile &&
- strlen($phonenumber) == 9 &&
- is_numeric($phonenumber)) {
- $result = true; //we have a 9 digit numeric number.
- }
- }
-
- // try to accept as Type VALIDATE_BE_PHONENUMBER_TYPE_MOBILE
- if ($type == VALIDATE_BE_PHONENUMBER_TYPE_ANY ||
- $type == VALIDATE_BE_PHONENUMBER_TYPE_MOBILE) {
- if ($is_mobile &&
- strlen($phonenumber) == 10 &&
- is_numeric($phonenumber)) {
- $result = true; //we have a 9 digit numeric number.
- }
- }
-
- //we need at least 9 digits
- if (preg_match('/^[+0-9]{9,}$/', $phonenumber)) {
- $phonenumber = substr($phonenumber, -9);
- //we only use the last 9 digits (so no troubles with
- //international numbers)
- if (strlen($phonenumber) >= 10) {
-
- }
- }
- return $result;
- }
-}
-?>
View
271 Validate/CA.php
@@ -1,271 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-/**
- * Specific validation methods for data used in Canada
- *
- * PHP Versions 4 and 5
- *
- * This source file is subject to the New BSD license, That is bundled
- * with this package in the file LICENSE, and is available through
- * the world-wide-web at
- * http://www.opensource.org/licenses/bsd-license.php
- * If you did not receive a copy of the new BSDlicense and are unable
- * to obtain it through the world-wide-web, please send a note to
- * pajoye@php.net so we can mail you a copy immediately.
- *
- * @category Validate
- * @package Validate_CA
- * @author Philippe Jausions <Philippe.Jausions@11abacus.com>
- * @copyright 1997-2005 Philippe Jausions
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id$
- * @link http://pear.php.net/package/Validate_CA
- */
-
-/**
- * Data validation class for Canada
- *
- * This class provides methods to validate:
- * - Social Insurance Number (aka SIN)
- * - Province code
- * - Telephone number
- * - Postal code
- *
- * @category Validate
- * @package Validate_CA
- * @author Philippe Jausions <Philippe.Jausions@11abacus.com>
- * @copyright 1997-2005 Philippe Jausions
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: @package_version@
- * @link http://pear.php.net/package/Validate_CA
- */
-class Validate_CA
-{
- /**
- * Validates a number according to Luhn check algorithm
- *
- * This function checks given number according Luhn check
- * algorithm. It is published on several places, see links:
- *
- * @param string $number number to check
- *
- * @return bool TRUE if number is valid, FALSE otherwise
- * @access protected
- * @static
- * @link http://www.webopedia.com/TERM/L/Luhn_formula.html
- * @link http://www.merriampark.com/anatomycc.htm
- * @link http://hysteria.sk/prielom/prielom-12.html#3 (Slovak language)
- * @link http://www.speech.cs.cmu.edu/~sburke/pub/luhn_lib.html (Perl lib)
- */
- function _luhn($number)
- {
- $len_number = strlen($number);
- $sum = 0;
- for ($k = $len_number % 2; $k < $len_number; $k += 2) {
- if ((intval($number{$k}) * 2) > 9) {
- $sum += (intval($number{$k}) * 2) - 9;
- } else {
- $sum += intval($number{$k}) * 2;
- }
- }
- for ($k = ($len_number % 2) ^ 1; $k < $len_number; $k += 2) {
- $sum += intval($number{$k});
- }
- return ($sum % 10) ? false : true;
- }
-
- /**
- * Validates a Canadian social insurance number (SIN)
- *