Standard Validation Classes
Zend Framework comes with a standard set of validation classes, which are ready for you to
use.
Alnum
Returns TRUE if and only if $value contains only
alphabetic and digit characters. This validator includes an option to also consider
white space characters as valid.
The alphabetic characters mean characters that makes up words in each language.
However, the English alphabet is treated as the alphabetic characters in following
languages: Chinese, Japanese, Korean. The language is specified by
Zend_Locale.
Alpha
Returns TRUE if and only if $value contains only
alphabetic characters. This validator includes an option to also consider white space
characters as valid.
Between
Returns TRUE if and only if $value is between
the minimum and maximum boundary values. The comparison is inclusive by default
($value may equal a boundary value), though this may be overridden in
order to do a strict comparison, where $value must be strictly
greater than the minimum and strictly less than the maximum.
Ccnum
Returns TRUE if and only if $value follows the
Luhn algorithm (mod-10 checksum) for credit card numbers.
The Ccnum validator has been deprecated in favor of the
CreditCard validator. For security reasons you should use
CreditCard instead of Ccnum.
Date
Returns TRUE if $value is a valid date of the
format 'YYYY-MM-DD'. If the optional locale option is set then the
date will be validated according to the set locale. And if the optional
format option is set this format is used for the validation. for
details about the optional parameters see Zend_Date::isDate().
Digits
Returns TRUE if and only if $value only contains
digit characters.
Float
Returns TRUE if and only if $value is a
floating-point value. Since Zend Framework 1.8 this validator takes into account the
actual locale from browser, environment or application wide set locale. You can of
course use the get/setLocale accessors to change the used locale or give it while
creating a instance of this validator.
GreaterThan
Returns TRUE if and only if $value is greater
than the minimum boundary.
Hex
Returns TRUE if and only if $value contains only
hexadecimal digit characters.
Iban
Returns TRUE if and only if $value contains a
valid IBAN (International Bank Account Number). IBAN numbers are validated against the
country where they are used and by a checksum.
There are two ways to validate IBAN numbers. As first way you can give a locale which
represents a country. Any given IBAN number will then be validated against this country.
isValid($iban)) {
// IBAN appears to be valid
} else {
// IBAN is invalid
foreach ($validator->getMessages() as $message) {
echo "$message\n";
}
}
]]>
This should be done when you want to validate IBAN numbers for a single countries. The
simpler way of validation is not to give a locale like shown in the next example.
isValid($iban)) {
// IBAN appears to be valid
} else {
// IBAN is invalid
}
]]>
But this shows one big problem: When you have to accept only IBAN numbers from one
single country, for example france, then IBAN numbers from other countries would also be
valid. Therefor just remember: When you have to validate a IBAN number against a defined
country you should give the locale. And when you accept all IBAN numbers regardless of
any country omit the locale for simplicity.
Int
Returns TRUE if and only if $value is a valid
integer. Since Zend Framework 1.8 this validator takes into account the actual locale
from browser, environment or application wide set locale. You can of course use the
get/setLocale accessors to change the used locale or give it while creating a instance
of this validator.
LessThan
Returns TRUE if and only if $value is less than
the maximum boundary.
Regex
Returns TRUE if and only if $value matches
against a regular expression pattern.
StringLength
Returns TRUE if and only if the string length of
$value is at least a minimum and no greater than a maximum (when the
max option is not NULL). The setMin()
method throws an exception if the minimum length is set to a value greater than the set
maximum length, and the setMax() method throws an exception if
the maximum length is set to a value less than the set minimum length. This class
supports UTF-8 and other character encodings, based on the current value of iconv.internal_encoding.
If you need a different encoding you can set it with the accessor methods getEncoding
and setEncoding.