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
* http://framework.zend.com/license/new-bsd
12
* If you did not receive a copy of the license and are unable to
13
* obtain it through the world-wide-web, please send an email
14
* to license@zend.com so we can send you a copy immediately.
17
* @package Zend_Validate
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
20
* @version $Id: Alpha.php 8064 2008-02-16 10:58:39Z thomas $
25
* @see Zend_Validate_Abstract
27
require_once 'Zend/Validate/Abstract.php';
32
* @package Zend_Validate
33
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
34
* @license http://framework.zend.com/license/new-bsd New BSD License
36
class Zend_Validate_Alpha extends Zend_Validate_Abstract
39
* Validation failure message key for when the value contains non-alphabetic characters
41
const NOT_ALPHA = 'notAlpha';
44
* Validation failure message key for when the value is an empty string
46
const STRING_EMPTY = 'stringEmpty';
49
* Whether to allow white space characters; off by default
53
public $allowWhiteSpace;
56
* Alphabetic filter used for validation
58
* @var Zend_Filter_Alpha
60
protected static $_filter = null;
63
* Validation failure message template definitions
67
protected $_messageTemplates = array(
68
self::NOT_ALPHA => "'%value%' has not only alphabetic characters",
69
self::STRING_EMPTY => "'%value%' is an empty string"
73
* Sets default option values for this instance
75
* @param boolean $allowWhiteSpace
78
public function __construct($allowWhiteSpace = false)
80
$this->allowWhiteSpace = (boolean) $allowWhiteSpace;
84
* Defined by Zend_Validate_Interface
86
* Returns true if and only if $value contains only alphabetic characters
88
* @param string $value
91
public function isValid($value)
93
$valueString = (string) $value;
95
$this->_setValue($valueString);
97
if ('' === $valueString) {
98
$this->_error(self::STRING_EMPTY);
102
if (null === self::$_filter) {
104
* @see Zend_Filter_Alpha
106
require_once 'Zend/Filter/Alpha.php';
107
self::$_filter = new Zend_Filter_Alpha();
110
self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
112
if ($valueString !== self::$_filter->filter($valueString)) {
113
$this->_error(self::NOT_ALPHA);