You are here

function _clientside_validation_set_regex in Clientside Validation 7

Same name and namespace in other branches
  1. 6 clientside_validation.module \_clientside_validation_set_regex()

Set validation rule for fields with regex validation from webform_validation

4 calls to _clientside_validation_set_regex()
clientside_validation_field_validation_regular in clientside_validation_field_validation/clientside_validation_field_validation.module
clientside_validation_html5 in clientside_validation_html5/clientside_validation_html5.module
clientside_validation_webform_add_webform_validation in clientside_validation_webform/clientside_validation_webform.module
Support webform_validation
hook_clientside_validation_rule_alter in ./clientside_validation.api.php
Some modules allow users to define extra validation rules defined in a hook. (e.g hook_webform_validation_validators()). To support these custom rules, clientside validation has its own hook, hook_clientside_validation_rule_alter. We had to use an…

File

./clientside_validation.module, line 1134
Add client side validation to forms.

Code

function _clientside_validation_set_regex($name, $title, &$js_rules, $expression, $message = '', $modifiers = "", $type = 'regex', $negate = FALSE) {
  $title = _clientside_validation_set_title($title);
  if (empty($message)) {
    $variables = array(
      'message' => '!title field does not match the required pattern.',
      'placeholders' => array(
        '!title' => $title,
      ),
      'error_type' => $type,
      'element_name' => $name,
    );
  }
  else {
    $variables = array(
      'message' => $message,
      'error_type' => $type,
      'element_name' => $name,
    );
  }
  $message = theme('clientside_error', $variables);
  $js_rules[$name]['regexMatch']['regex'] = array(
    $expression,
  );
  $js_rules[$name]['regexMatch']['negate'] = $negate;
  if (!empty($modifiers)) {
    $js_rules[$name]['regexMatch']['regex'][] = $modifiers;
  }
  $js_rules[$name]['messages']['regexMatch'] = $message;
}