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.
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 $
23 * @see Zend_Validate_Abstract
25 require_once 'Zend/Validate/Abstract.php';
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';
40 * Whether to allow white space characters; off by default
45 public $allowWhiteSpace;
48 * Alphabetic filter used for validation
50 * @var Zend_Filter_Alpha
52 protected static $_filter = null;
55 * Validation failure message template definitions
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"
66 * Sets default option values for this instance
68 * @param boolean $allowWhiteSpace
71 public function __construct($allowWhiteSpace = false)
73 $this->allowWhiteSpace
= (boolean
) $allowWhiteSpace;
77 * Returns the allowWhiteSpace option
81 public function getAllowWhiteSpace()
83 return $this->allowWhiteSpace
;
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;
99 * Defined by Zend_Validate_Interface
101 * Returns true if and only if $value contains only alphabetic characters
103 * @param string $value
106 public function isValid($value)
108 if (!is_string($value)) {
109 $this->_error(self
::INVALID
);
113 $this->_setValue($value);
116 $this->_error(self
::STRING_EMPTY
);
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
);