You are here

function fapi_validation_validator_regexp in Form API Validation 8

1 string reference to 'fapi_validation_validator_regexp'
fapi_validation_fapi_validation_validators in src/fapi_validators/fapi_validators.inc
Implementation of hook_fapi_validation_validators

File

src/fapi_validators/fapi_validators.inc, line 143

Code

function fapi_validation_validator_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);
}