*/ WBClass::load('WBPAT_Forms_Rule'); /** * patForms Rule ConfigExists * * Check whether config exists. Use loader to load config and check whether loading fails * * @version 0.1.0 * @package Wombat * @subpackage patForms */ class patForms_Rule_PregMatch extends WBPAT_Forms_Rule { /** * default config values * - regex * - match must match or must not match * * @var array */ protected $config = array( 'regex' => '/^\w+$/', 'match' => 'yes' ); /** * Initialize validation codes using gettext * * @access protected * @return bool $success Always returns true. * @see $attributeDefaults */ public function loadValidatiorErrorCodes() { $this->validatorErrorCodes = array( 1 => patI18n::dgettext('wombat', 'Format mismatch'), ); return true; } /** * method called by patForms or any patForms_Element to validate the * element or the form. * * @param patForms_Element $form object * @return bool true on sucess */ public function applyRule(&$element, $type = PATFORMS_RULE_AFTER_VALIDATION) { $value = $element->getValue(); if (empty($value)) { return true; } $match = preg_match($this->config['regex'], $value); // inverse if ('no' == $this->config['match']) { $match = !$match; } if ($match) { return true; } $this->addValidationError(1); return false; } } ?>