You are here

function webform_validation_webform_validation_validators in Webform Validation 6

Same name and namespace in other branches
  1. 7 webform_validation.validators.inc \webform_validation_webform_validation_validators()

Implementation of hook_webform_validation_validators().

This function returns an array of validators, in the validator key => options array form. Possible options:

  • name (required): name of the validator
  • component types (required): defines which component types can be validated by this validator. Specify 'all' to allow all types
  • custom_error (optional): define whether a user can specify a custom error message upon creating the validation rule.
  • custom_data (optional): define whether custom data can be added to the validation rule
  • min_components (optional): define the minimum number of components to be selected for creating a validation rule
  • max_components (optional): define the maximum number of components to be selected for creating a validation rule
  • description (optional): provide a descriptive explanation about the validator

File

./webform_validation.validators.inc, line 21
Provides validation functionality and hooks

Code

function webform_validation_webform_validation_validators() {
  return array(
    'numeric' => array(
      'name' => "Numeric values",
      'component_types' => array(
        'textfield',
        'hidden',
      ),
      'custom_data' => array(
        'label' => t('Specify numeric validation range'),
        'description' => t('Optionally specify the minimum-maximum range to validate the user-entered numeric value against.') . ' ' . t('Usage') . ':' . theme('item_list', array(
          t('empty: no value validation'),
          t('"100": greater than or equal to 100'),
          t('"|100": less than or equal to 100 (including negative numbers)'),
          t('"0|100": greater than or equal to 0 & less than or equal to 100'),
          t('"10|100": greater than or equal to 10 & less than or equal to 100'),
          t('"-100|-10": greater than or equal to -100 & less than or equal to -10'),
        )),
        'required' => FALSE,
      ),
      'description' => t('Verifies that user-entered values are numeric, with the option to specify min and / or max values.'),
    ),
    'min_length' => array(
      'name' => "Minimum length",
      'component_types' => array(
        'textfield',
        'textarea',
        'email',
        'hidden',
      ),
      'custom_data' => array(
        'label' => t('Minimum number of characters'),
        'description' => t('Specify the minimum number of characters that have to be entered to pass validation.'),
      ),
      'description' => t('Verifies that a user-entered value contains at least the specified number of characters'),
    ),
    'max_length' => array(
      'name' => "Maximum length",
      'component_types' => array(
        'textfield',
        'textarea',
        'email',
        'hidden',
      ),
      'custom_data' => array(
        'label' => t('Maximum number of characters'),
        'description' => t('Specify the maximum number of characters that can be entered to pass validation.'),
      ),
      'description' => t('Verifies that a user-entered value contains at most the specified number of characters'),
    ),
    'min_words' => array(
      'name' => "Minimum number of words",
      'component_types' => array(
        'textfield',
        'textarea',
        'hidden',
      ),
      'custom_data' => array(
        'label' => t('Minimum number of words'),
        'description' => t('Specify the minimum number of words that have to be entered to pass validation. Words are defined as strings of letters separated by spaces.'),
      ),
      'description' => t('Verifies that a user-entered value contains at least the specified number of words'),
    ),
    'max_words' => array(
      'name' => "Maximum number of words",
      'component_types' => array(
        'textfield',
        'textarea',
        'hidden',
      ),
      'custom_data' => array(
        'label' => t('Maximum number of words'),
        'description' => t('Specify the maximum number of words that have to be entered to pass validation. Words are defined as strings of letters separated by spaces.'),
      ),
      'description' => t('Verifies that a user-entered value contains at most the specified number of words'),
    ),
    'equal' => array(
      'name' => "Equal values",
      'component_types' => array(
        'textfield',
        'email',
        'select',
        'hidden',
      ),
      'min_components' => 2,
      'description' => t('Verifies that all specified components contain equal values'),
    ),
    'unique' => array(
      'name' => "Unique values",
      'component_types' => array(
        'textfield',
        'email',
        'select',
        'hidden',
      ),
      'min_components' => 2,
      'description' => t('Verifies that all specified components contain unique values'),
    ),
    'specific_value' => array(
      'name' => "Specific value(s)",
      'component_types' => array(
        'select',
        'textfield',
        'textarea',
        'email',
        'hidden',
      ),
      'custom_error' => TRUE,
      'custom_data' => array(
        'label' => t('(Key) value'),
        'description' => t('Specify the specific value(s) you want the component to contain. Separate multiple options by a comma. For components that have keys, use the key value instead.'),
      ),
      'max_components' => 1,
      'description' => t('Verifies that the specified component contains a defined value'),
    ),
    'not_default_value' => array(
      'name' => "Not default value",
      'component_types' => array(
        'select',
        'textfield',
        'textarea',
        'email',
        'hidden',
      ),
      'custom_error' => TRUE,
      'description' => t('Verifies that the user-entered value is not the default value for that component.'),
    ),
    'oneoftwo' => array(
      'name' => "Require at least one of two fields",
      'component_types' => array(
        'textfield',
        'textarea',
        'email',
        'select',
      ),
      'min_components' => 2,
      'max_components' => 2,
      'description' => t('Forces the user to specify / select at least one of two selected webform components'),
    ),
    'oneofseveral' => array(
      'name' => "Require at least one of several fields",
      'component_types' => array(
        'textfield',
        'textarea',
        'email',
        'select',
      ),
      'min_components' => 2,
      'description' => t('Forces the user to specify / select at least one of several selected webform components'),
    ),
    'select_min' => array(
      'name' => "Minimum number of selections required",
      'component_types' => array(
        'select',
      ),
      'custom_data' => array(
        'label' => t('Minimum number of selections'),
        'description' => t('Specify the minimum number of options a user should select.'),
      ),
      'description' => t('Forces the user to select at least a defined number of options from the specified webform components'),
    ),
    'select_max' => array(
      'name' => "Maximum number of selections allowed",
      'component_types' => array(
        'select',
      ),
      'custom_data' => array(
        'label' => t('Maximum number of selections'),
        'description' => t('Specify the maximum number of options a user can select.'),
      ),
      'description' => t('Forces the user to select at most a defined number of options from the specified webform components'),
    ),
    'select_exact' => array(
      'name' => "Exact number of selections required",
      'component_types' => array(
        'select',
      ),
      'custom_data' => array(
        'label' => t('Number of selections'),
        'description' => t('Specify how many options a user can select.'),
      ),
      'description' => t('Forces the user to select exactly the defined number of options from the specified webform components'),
    ),
    'plain_text' => array(
      'name' => "Plain text (disallow tags)",
      'component_types' => array(
        'textfield',
        'textarea',
        'email',
        'hidden',
      ),
      'description' => t("Verifies that user-entered data doesn't contain HTML tags"),
    ),
    'regex' => array(
      'name' => "Regular expression",
      'component_types' => array(
        'textfield',
        'textarea',
        'email',
        'hidden',
      ),
      'custom_error' => TRUE,
      'custom_data' => array(
        'label' => t('Regex code'),
        'description' => t('Specify regex code to validate the user input against.'),
      ),
      'description' => t("Validates user-entered text against a specified regular expression. Note: don't include delimiters such as /."),
    ),
    'must_be_empty' => array(
      'name' => "Must be empty",
      'component_types' => array(
        'textfield',
        'hidden',
      ),
      'description' => t('Verifies that a specified textfield remains empty - Recommended use case: used as an anti-spam measure by hiding the element with CSS'),
    ),
    'blacklist' => array(
      'name' => "Words blacklist",
      'component_types' => array(
        'textfield',
        'textarea',
        'email',
        'hidden',
      ),
      'custom_error' => TRUE,
      'custom_data' => array(
        'label' => t('Blacklisted words'),
        'description' => t('Specify illegal words, seperated by commas. Make sure to escape reserved regex characters with an escape (\\) character.'),
      ),
      'description' => t("Validates that user-entered data doesn't contain any of the specified illegal words"),
    ),
    'username' => array(
      'name' => "Must match a username",
      'component_types' => array(
        'textfield',
        'hidden',
      ),
      'description' => t("Validates that user-entered data matches a username"),
    ),
  );
}