API16

JFormRule/test: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
No edit summary
m preparing for archive only
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
Method to test the value.
Method to test the value.


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JFormRule/test|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JFormRule/test}}
 
<! removed transcluded page call, red link never existed >


===Syntax===
===Syntax===
Line 60: Line 58:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JFormRule/test|Edit See Also]]<nowiki>]</nowiki>
<! removed transcluded page call, red link never existed >
</span>
{{SeeAlso:JFormRule/test}}


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=test
  category=test
  category=JFormRule
  category=JFormRule
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>
[[Category:Archived pages API16]]

Latest revision as of 01:43, 25 March 2017

Description

Method to test the value.


<! 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 transcluded page call, red link never existed >

Examples

Code Examples