<?php
Require_once ("zend/loader.php");
The introduction of the validator class and the function Class (INT) of the calibrator, and the custom interface class;
Zend_loader::loadclass (' zend_validate ');
Zend_loader::loadclass (' Zend_validate_int ');
Zend_loader::loadclass (' Zend_validate_interface ');
Add custom Validator Feature Class (gongbeinum) [Common multiple]
Class Gongbeinum implements Zend_validate_interface
{
Declaring an error message report property in an interface
Protected $_messages = Array ();
The calibration method in the Declaration interface
Public Function IsValid ($num)
{
if (!) ( $num%3==0) &&! ($num%5==0))
{
If the checksum fails, the error message returns the value to the error message report property
$this-> _messages[] = "The number you entered is not the common multiple of 3 and 5!" ";
Terminate program
return false;
}
return True
return true;
}
To define an error method for an interface
Public Function Getmessages ()
{
return $this-> _messages;
}
Define extraction Error message (none)
Public Function geterrors ()
{
}
}
Class definition detection Common multiple method
function Check_num ($num)
{
Instantiating the Validator class
$Validate = new Zend_validate ();
Add validator function class, add custom Validator function class, form validator chain
$Validate-> Addvalidator (New Zend_validate_int ())
-> Addvalidator (New Gongbeinum ());
Checksum parameters
if (! $Validate-> isValid ($num))
{
If error loops error message and outputs
foreach ($Validate-> getmessages () as $value)
{
Echo $value. "<br>";
return false;
}
}
}
Specify the value of the judgment
$num 1 = ' 15 ';
The method of verifying the running school
Check_num ($num 1);
?>