Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

cValidator

cValidator provides the functionality to validate values against a fixed set of values. For example you can define a regular expression and test values against it. 

If you want to write validation classes your class have to inherit from the cValidatorAbstract class. The minimal feature of your class should be the implementation of the isValid method with the logic if a given value matches the validation or not.

Class diagramm

Methods

Method nameDescription
setOptions(options)This method can be used to set an array validation options
setOption(name, value)This method can be used to set an validation option
getOption(name)This method returns a option by its name

getErrors()

This method returns errors
isValid(value)This method can be used to run a value against your specified options

 

How to use

At first you need to get an validator object. To reach this goal you have to call the static getInstance method from the cValidatorFactory class.

With the first parameter parameter you can choose whitch instance the factory will create. For example if you want to get an instance of the cValidatorEmail class just type the parameter 'email'.

 

$email = cValidatorFactory::getInstance('email');
$email->isValid('contenido@contenido.org');

The call of the isValid method above returns true.

$email = cValidatorFactory::getInstance('email');
$email->isValid('contenido@@contenido.org');

The call of the isValid method above returns false.

$regex = cValidatorFactory::getInstance('regex');
$regex->setOption('pattern', '/CONTENIDO/');
$regex->isValid('CONTENIDO 4.9');

The call of the isValid method above returns true.

$regex = cValidatorFactory::getInstance('regex');
$regex->setOption('pattern', '/CONTENIDO/');
$regex->isValid('CONDENITO 4.9');

The call of the isValid method above returns false.

Adding validator classes

  • No labels