eZPublish  3.8
eZInputValidator Class Reference

Input text validation and correction. More...

+ Inheritance diagram for eZInputValidator:

Public Member Functions

 eZInputValidator ()
 
 fixup (&$text)
 
 validate ($text)
 

Detailed Description

Input text validation and correction.

This is the base class for doing validation of input text and eventually correction. The general eZRegExpValidator can be used for most validations by supplying it with a regexp rule set, for more advanced validation you can use the eZIntegerValidator which can validate integers withing ranges.

For creating your own validators you can either inherit this class or any of the advanced classes. The inherited class must implement the validate() function for validation and fixup() for fixing text to be acceptable.

A validation will return a state which can either be Accepted, Intermediate or Invalid. Accepted means that the text can be used without modification, Invalid means that the text cannot be used at any cost while Intermediate means that the text can be used if it's fixed with the fixup() function.

Example of a simple integer validator

class IntegerValidator
{
function IntegerValidator()
{
}
function validate( $text )
{
}
function fixup( &$text )
{
}
}

Example of a boolean validator

class BooleanValidator
{
function BooleanValidator()
{
}
function validate( $text )
{
if ( strtolower( $text ) == "true" or
strtolower( $text ) == "false" )
if ( is_numeric( $text ) )
}
function fixup( &$text )
{
$text = ( $text == 0 ? "false" : "true" );
}
}

Member Function Documentation

eZInputValidator::eZInputValidator ( )

Default constructor, does nothing.

Referenced by eZRegExpValidator\eZRegExpValidator().

eZInputValidator::fixup ( $text)

Tries to fix the text $text which was previously marked as EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE so that it can be seen as EZ_INPUT_VALIDATOR_STATE_ACCEPTED.

eZInputValidator::validate (   $text)

Tries to validate to the text $text and returns one of the validator states EZ_INPUT_VALIDATOR_STATE_ACCEPTED, EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE or EZ_INPUT_VALIDATOR_STATE_INVALID. This returns EZ_INPUT_VALIDATOR_STATE_ACCEPTED as default and must be reimplemented in real valiators.


The documentation for this class was generated from the following file: