*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Validate / Alpha.php
blobce1f01872ff7ff9d63cdffe571e9ef5c0ec7fb66
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_Validate
17 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id: Alpha.php 16223 2009-06-21 20:04:53Z thomas $
22 /**
23 * @see Zend_Validate_Abstract
25 require_once 'Zend/Validate/Abstract.php';
27 /**
28 * @category Zend
29 * @package Zend_Validate
30 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
33 class Zend_Validate_Alpha extends Zend_Validate_Abstract
35 const INVALID = 'alphaInvalid';
36 const NOT_ALPHA = 'notAlpha';
37 const STRING_EMPTY = 'stringEmpty';
39 /**
40 * Whether to allow white space characters; off by default
42 * @var boolean
43 * @depreciated
45 public $allowWhiteSpace;
47 /**
48 * Alphabetic filter used for validation
50 * @var Zend_Filter_Alpha
52 protected static $_filter = null;
54 /**
55 * Validation failure message template definitions
57 * @var array
59 protected $_messageTemplates = array(
60 self::INVALID => "Invalid type given, value should be a string",
61 self::NOT_ALPHA => "'%value%' has not only alphabetic characters",
62 self::STRING_EMPTY => "'%value%' is an empty string"
65 /**
66 * Sets default option values for this instance
68 * @param boolean $allowWhiteSpace
69 * @return void
71 public function __construct($allowWhiteSpace = false)
73 $this->allowWhiteSpace = (boolean) $allowWhiteSpace;
76 /**
77 * Returns the allowWhiteSpace option
79 * @return boolean
81 public function getAllowWhiteSpace()
83 return $this->allowWhiteSpace;
86 /**
87 * Sets the allowWhiteSpace option
89 * @param boolean $allowWhiteSpace
90 * @return Zend_Filter_Alpha Provides a fluent interface
92 public function setAllowWhiteSpace($allowWhiteSpace)
94 $this->allowWhiteSpace = (boolean) $allowWhiteSpace;
95 return $this;
98 /**
99 * Defined by Zend_Validate_Interface
101 * Returns true if and only if $value contains only alphabetic characters
103 * @param string $value
104 * @return boolean
106 public function isValid($value)
108 if (!is_string($value)) {
109 $this->_error(self::INVALID);
110 return false;
113 $this->_setValue($value);
115 if ('' === $value) {
116 $this->_error(self::STRING_EMPTY);
117 return false;
120 if (null === self::$_filter) {
122 * @see Zend_Filter_Alpha
124 require_once 'Zend/Filter/Alpha.php';
125 self::$_filter = new Zend_Filter_Alpha();
128 self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
130 if ($value !== self::$_filter->filter($value)) {
131 $this->_error(self::NOT_ALPHA);
132 return false;
135 return true;