Actions

API16

JFormRule/test

From Joomla! Documentation

< API16:JFormRule
Revision as of 21:53, 13 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Method to test the value.

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

test(&$field, &$values)
Parameter Name Default Value Description
&$field $field A reference to the form field.
&$values $values The values to test for validiaty.

Returns

boolean True if the value is valid, false otherwise.

Defined in

libraries/joomla/form/formrule.php

Importing

jimport( 'joomla.form.formrule' );

Source Body

public function test(&$field, &$values)
{
        $return = false;
        $name   = (string)$field->attributes()->name;
 
        // Check for a valid regex.
        if (empty($this->_regex)) {
                throw new JException('Invalid Form Rule :: '.get_class($this));
        }
 
        // Add unicode property support if available.
        if (JCOMPAT_UNICODE_PROPERTIES) {
                $this->_modifiers = strpos($this->_modifiers, 'u') ? $this->_modifiers : $this->_modifiers.'u';
        }
 
        // Test the value against the regular expression.
        if (preg_match('#'.$this->_regex.'#'.$this->_modifiers, $values[$name])) {
                $return = true;
        }
 
        return $return;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />