JFormRule/test: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Method to test the value.
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>
</spa... |
No edit summary |
||
Line 17: | Line 17: | ||
!Description | !Description | ||
|- | |- | ||
| | | &$field | ||
| | | | ||
| $field A reference to the form field. | | $field A reference to the form field. | ||
|- | |- | ||
| | | &$values | ||
| | | | ||
| $values The values to test for validiaty. | | $values The values to test for validiaty. |
Revision as of 10:15, 30 March 2010
Description
Method to test the value.
Template:Description:JFormRule/test
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;
}
[Edit See Also] Template:SeeAlso:JFormRule/test
Examples
<CodeExamplesForm />