arrows-dumb
arrows-dumb
Pear Validate Rules

PEAR Validation

Function Property Description
Email This method validate email addresses against both the general format and the one described in RFC 822.
check_domain (boolean) Check or not if the domain exists
use_rfc822 (boolean) Apply the full RFC822 grammar.
fullTLDValidation (boolean) All top-level domains.
VALIDATE_GTLD_EMAILS (boolean) Only generic top-level domains
VALIDATE_CCTLD_EMAILS (boolean) Only country code top-level domains.
VALIDATE_ITLD_EMAILS (boolean) Only international top-level domains
Example require_once 'Validate.php';
$email = '"Doe, John" ';
if (Validate::email($email, array('use_rfc822' => true))) {
echo 'Valid!';
} else {
echo $email . ' failed.'; }
$email = 'info@example.com';
if (Validate::email($email, array('check_domain' => 'true'))) {
echo $email . ' is valid and domain exists';
}
Number validation This method validates numbers. Decimal or not, max and min.
decimal (mixed) Decimal chars or false when decimal not allowed. For example ",." to allow both "." and ",".
dec_prec (int) Number of allowed decimals.
min (float) Minimum value
max (float) Maximum value
if (Validate::number(8.0004, array('decimal' => '.', 'dec_prec' => 4))) {
echo 'Valid number';
}
$number = '-8,1';
if (Validate::number($number, array('decimal' => '.,', 'min' => -9, 'max' => -7 ))) {
echo 'Valid';
} else {
echo 'Invalid';
}
String validation This method validates string using the given format.
VALIDATE_NUM Number (0-9).
VALIDATE_SPACE Space /s
VALIDATE_ALPHA_LOWER Lower case alphabets (a-z).
VALIDATE_ALPHA_UPPER Upper case alphabets (A-Z).
VALIDATE_ALPHA Alphabets (a-Z).
VALIDATE_EALPHA_LOWER Lower case letters with an accent (French, ...), umlauts (German), special characters (e.g. Skandinavian) and VALIDATE_ALPHA_LOWER.
VALIDATE_EALPHA_UPPER Upper case letters with an accent (French, ...), umlauts (German), special characters (e.g. Skandinavian) and VALIDATE_ALPHA_UPPER
VALIDATE_EALPHA Letters with an accent (French, ...), umlauts (German), special characters (e.g. Skandinavian) and VALIDATE_ALPHA.
VALIDATE_PUNCTUATION Punctuation .,;:&"?!', "(" and ")".
VALIDATE_NAME VALIDATE_EALPHA, VALIDATE_SPACE, "'" and "-".
VALIDATE_STREET VALIDATE_NUM and VALIDATE_NAME, "\./", "º" and "ª".
min_length (int) Minimum length
max_length (int) Maximum length.
if (Validate::string("1984 GEORGE ORWELL", array(
'format' => VALIDATE_NUM . VALIDATE_SPACE . VALIDATE_ALPHA_UPPER))) {
echo 'Valid!';
} else {
echo 'Invalid!';
}
Date Date formats
format Format of the date (%d-%m-%Y) or rfc822_compliant
min The date has to be greater than this array ($day, $month, $year) or PEAR::Date object),
max The date has to be smaller than this array ($day, $month, $year) or PEAR::Date object),
URI RFC2396
Further total confusion PEAR Validate