6.5.tgz (16,296 bytes)
......done: 16,296 bytes
downloading Date-1.4.6.tgz ...
Starting to download Date-1.4.6.tgz (53,535 bytes)
...done: 53,535 bytes
install ok: channel://pear.php.net/Date-1.4.6
install ok: channel://pear.php.net/Validate-0.6.5
The -a will result in the optional package dependency Date also being installed. If you
don??™t plan on validating dates, you can omit this option. Also, in this example the version
number is appended to the package; this is because at the time this was written, Validate
was still in a beta state. Once it reaches a stable version there will be no need to include
the version number.
Validating a String
Some data should consist only of numeric characters, alphabetical characters, a certain
range of characters, or maybe even all uppercase or lowercase letters. You can validate
such rules and more using Validate??™s string() method:
// Include the Validate package
require_once "Validate.php";
// Retrieve the provided username
$username = $_POST['username'];
// Instantiate the Validate class
$validate = new Validate();
// Determine if address is valid
if($validate->string($username, array("format" => VALIDATE_ALPHA,
"min_length"=> "3", "max_length" => "15")))
echo "Valid username!";
else
echo "The username must be between 3 and 15 characters in length!";
?>
558 CHAPTER 21 ?– SECURE PHP PROGRAMMING
Validating an E-mail Address
Validating an e-mail address??™s syntax is a fairly difficult matter, requiring the use of a
somewhat complex regular expression.
Pages:
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642