Overview

Namespaces

  • Jyxo
    • Beholder
      • TestCase
    • Gettext
      • Parser
    • Input
      • Chain
      • Filter
      • Validator
    • Mail
      • Email
        • Attachment
      • Parser
      • Sender
    • Rpc
      • Json
      • Xml
    • Shell
    • Spl
    • Svn
    • Time
    • Webdav
  • PHP

Classes

  • AbstractValidator
  • Callback
  • Equals
  • InArray
  • IsArray
  • IsBankAccountNumber
  • IsBirthNumber
  • IsCompanyId
  • IsCountryCode
  • IsDate
  • IsDateTime
  • IsEmail
  • IsIban
  • IsInt
  • IsIpV4
  • IsIpV6
  • IsNumeric
  • IsPhone
  • IsTaxId
  • IsUrl
  • IsZipCode
  • LessThan
  • NotEmpty
  • Regex
  • StringLengthBetween
  • StringLengthGreaterThan
  • StringLengthLessThan
  • Upload

Interfaces

  • ErrorMessage

Exceptions

  • Exception
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
 1: <?php
 2: 
 3: /**
 4:  * Jyxo PHP Library
 5:  *
 6:  * LICENSE
 7:  *
 8:  * This source file is subject to the new BSD license that is bundled
 9:  * with this package in the file license.txt.
10:  * It is also available through the world-wide-web at this URL:
11:  * https://github.com/jyxo/php/blob/master/license.txt
12:  */
13: 
14: namespace Jyxo\Input\Validator;
15: 
16: /**
17:  * (Czech) bank number validator.
18:  *
19:  * @category Jyxo
20:  * @package Jyxo\Input
21:  * @subpackage Validator
22:  * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
23:  * @license https://github.com/jyxo/php/blob/master/license.txt
24:  * @author Jaroslav HanslĂ­k
25:  */
26: class IsBankAccountNumber extends \Jyxo\Input\Validator\AbstractValidator
27: {
28:     /**
29:      * Validates a value.
30:      *
31:      * @param mixed $value Input value
32:      * @return boolean
33:      */
34:     public function isValid($value)
35:     {
36:         if (!preg_match('~^(?:(\d{1,6})-)?(\d{2,10})/(\d{4})$~i', (string) $value, $matches)) {
37:             return false;
38:         }
39: 
40:         list(, $prefix, $base, $bankCode) = $matches;
41: 
42:         // Bank codes valid in the Czech Republic on 2008-09-01
43:         static $bankCodes = array(
44:             '0100', '0300', '0400', '0600', '0700', '0800', '2010', '2020', '2030', '2040',
45:             '2050', '2070', '2100', '2200', '2400', '2600', '2700', '3500', '4000', '4300',
46:             '5000', '5400', '5500', '5800', '6000', '6100', '6200', '6210', '6300', '6700',
47:             '6800', '7910', '7940', '7950', '7960', '7970', '7980', '7990', '8030', '8040',
48:             '8060', '8090', '8150', '8200'
49:         );
50: 
51:         // Valid bank code
52:         if (!in_array($bankCode, $bankCodes)) {
53:             return false;
54:         }
55: 
56:         // Prefix check
57:         $prefix = str_pad($prefix, 6, '0', STR_PAD_LEFT);
58:         $mod = ($prefix[0] * 10 + $prefix[1] * 5 + $prefix[2] * 8 + $prefix[3] * 4 + $prefix[4] * 2 + $prefix[5] * 1) % 11;
59:         if (0 !== $mod) {
60:             return false;
61:         }
62: 
63:         // Base number part check
64:         $base = str_pad($base, 10, '0', STR_PAD_LEFT);
65:         $mod = ($base[0] * 6 + $base[1] * 3 + $base[2] * 7 + $base[3] * 9 + $base[4] * 10 + $base[5] * 5 + $base[6] * 8 + $base[7] * 4 + $base[8] * 2 + $base[9] * 1) % 11;
66:         if (0 !== $mod) {
67:             return false;
68:         }
69: 
70:         return true;
71:     }
72: }
73: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0