You are here

function fapi_validation_rule_regexp in Form API Validation 7.2

Same name and namespace in other branches
  1. 6 fapi_validation.module \fapi_validation_rule_regexp()
  2. 7 fapi_validation.module \fapi_validation_rule_regexp()
1 string reference to 'fapi_validation_rule_regexp'
fapi_validation_fapi_validation_rules in ./fapi_validation.module
Implementation of hook_fapi_validation_rules

File

./fapi_validation.module, line 333

Code

function fapi_validation_rule_regexp($value, $params) {

  // Some FAPI elements types, such as those provided by the Date API module,
  // will come in as an array (with date in one element and time in another). To
  // handle this use-case we simply implode them into a string.
  if (is_array($value)) {

    // Using array filter ensures that empty array elements do not cause an
    // extra space to be added to the value. We can't use trim to fix this issue
    // cause trim will remove all trailing whitespace in a string, which may be
    // meaningful.
    $value = implode(' ', array_filter($value));
  }
  return (bool) preg_match($params[0], (string) $value);
}