The addCustomRegexp hook is triggered when an unknown regular expression is found. It passes the name of the regexp, the current value and the widget object as arguments and expects a boolean return value.


from Contao 2.6.2.


  1. string $strRegexp

    The unknown regular expression string.

  2. mixed $varValue

    The input value to be validated.

  3. Widget $objWidget

    Form widget which is handling this input value. Use the widget's properties to retrieve information about the field configuration.



// config.php
$GLOBALS['TL_HOOKS']['addCustomRegexp'][] = array('MyClass', 'myAddCustomRegexp');

// MyClass.php
public function myAddCustomRegexp($strRegexp, $varValue, Widget $objWidget)
    if ($strRegexp == 'postal')
        if (!preg_match('/^[0-9]{4,6}$/', $varValue))
            $objWidget->addError('Field ' . $objWidget->label . ' should be a postal code.');

        return true;

    return false;

More information


See also

results matching ""

    No results matching ""