previousHTML_QuickForm::setElementError() (Previous) (Next) HTML_QuickForm::getRegisteredRules()next

View this page in Last updated: Sun, 18 Oct 2009
English | Brazilian Portuguese | Chinese | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Turkish

HTML_QuickForm::registerRule()

HTML_QuickForm::registerRule() – Registers a new validation rule

Synopsis

require_once 'HTML/QuickForm.php';

void HTML_QuickForm::registerRule ( string $ruleName , string $type , string $data1 , string $data2 = null )

Description

Registers a new validation rule

Parameter

string $ruleName

Name of validation rule

string $type

Either: 'regex' or 'callback' ('function' is also kept for backward compatibility). If registering a subclass of HTML_QuickForm_Rule you can pass anything here, preferrably NULL or empty string.

string $data1

Name of function, regular expression, classname of HTML_QuickForm_Rule subclass or an instance of such class.

The callback function needs to return true or false, determining if the rule is passed or not.

string $data2

Object parent of above function, name of the file containing the subclass of HTML_QuickForm_Rule.

Throws

throws no exceptions thrown

Note

since 1.0

This function can not be called statically.

previousHTML_QuickForm::setElementError() (Previous) (Next) HTML_QuickForm::getRegisteredRules()next

Download Documentation Last updated: Sun, 18 Oct 2009
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
Note by: kguest
One example of this is:

$form->registerRule('phone','regex', '/^[\d\-\.\s]+$/');

this rule will only allow numeric phone numbers with an optional separator between each grouping of numbers.
Separator may be either a space, hyphen, full-stop/period.