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 (Czech) Tax ID.
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 IsTaxId extends \Jyxo\Input\Validator\AbstractValidator
27: {
28:     /**
29:      * Strict check.
30:      *
31:      * If turned on, validity of IČ/birth number is also performed. If not, only length is checked.
32:      *
33:      * @var boolean
34:      */
35:     private $strict = true;
36: 
37:     /**
38:      * Constructor.
39:      *
40:      * @param boolean $strict Turns strict checking on or off.
41:      */
42:     public function __construct($strict = true)
43:     {
44:         $this->strict = (bool) $strict;
45:     }
46: 
47:     /**
48:      * Validates a value.
49:      *
50:      * @param mixed $value Input value
51:      * @return boolean
52:      */
53:     public function isValid($value)
54:     {
55:         // Removes spaces
56:         $taxId = preg_replace('~\s+~', '', (string) $value);
57: 
58:         $sub = '';
59:         // New Tax ID format since 1st May 2004
60:         if (preg_match('~^CZ(\d{8,10})$~', $taxId, $matches)) {
61:             $sub = $matches[1];
62:             // But to be sure we try the old one as well
63:         } elseif (preg_match('~^\d{3}-(\d{8,10})$~', $taxId, $matches)) {
64:             $sub = $matches[1];
65:         }
66:         if (!empty($sub)) {
67:             // Strict checking off - allows the so called "own numbers"
68:             if (!$this->strict) {
69:                 return true;
70:             }
71: 
72:             // Checks if it is a valid IČ
73:             if (IsCompanyId::validate($sub)) {
74:                 return true;
75:             }
76: 
77:             // Checks if it is a valid birth number
78:             if (IsBirthNumber::validate($sub)) {
79:                 return true;
80:             }
81:         }
82: 
83:         return false;
84:     }
85: }
86: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0