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:  * Validates IČ (Czech company number).
18:  *
19:  * Taken from David Grudl's http://latrine.dgx.cz/jak-overit-platne-ic-a-rodne-cislo
20:  *
21:  * @category Jyxo
22:  * @package Jyxo\Input
23:  * @subpackage Validator
24:  * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
25:  * @license https://github.com/jyxo/php/blob/master/license.txt
26:  * @author Jaroslav Hanslík
27:  */
28: class IsCompanyId extends \Jyxo\Input\Validator\AbstractValidator
29: {
30:     /**
31:      * Validates a value.
32:      *
33:      * @param mixed $value Input value
34:      * @return boolean
35:      */
36:     public function isValid($value)
37:     {
38:         // Removes spaces
39:         $companyId = preg_replace('~\s+~', '', (string) $value);
40: 
41:         // Only numbers
42:         if (!preg_match('~^\d{8}$~', $companyId)) {
43:             return false;
44:         }
45: 
46:         // Checksum
47:         $a = 0;
48:         for ($i = 0; $i < 7; $i++) {
49:             $a += $companyId[$i] * (8 - $i);
50:         }
51: 
52:         $a = $a % 11;
53:         if (0 === $a) {
54:             $c = 1;
55:         } elseif (10 === $a) {
56:             $c = 1;
57:         } elseif (1 === $a) {
58:             $c = 0;
59:         } else {
60:             $c = 11 - $a;
61:         }
62: 
63:         if ((int) $companyId[7] !== $c) {
64:             return false;
65:         }
66: 
67:         return true;
68:     }
69: }
70: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0