function field_validation_field_validation_validators in Field Validation 7
Implements hook_field_validation_validators().
This function returns an array of validators, in the validator key => options array form. Possible options:
- name (required): name of the validator
- field types (required): defines which field 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
- description (optional): provide a descriptive explanation about the validator
File
- ./
field_validation.validators.inc, line 19 - Provides validation functionality and hooks
Code
function field_validation_field_validation_validators() {
return array(
'regex' => array(
'name' => "Regular expression",
'field_types' => array(
'textfield',
'textarea',
),
'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 /."),
),
'numeric' => array(
'name' => "Numeric values",
'field_types' => array(
'textfield',
),
'custom_error' => TRUE,
'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(
'items' => 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",
'field_types' => array(
'textfield',
'textarea',
),
'custom_error' => TRUE,
'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",
'field_types' => array(
'textfield',
'textarea',
),
'custom_error' => TRUE,
'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",
'field_types' => array(
'textfield',
'textarea',
),
'custom_error' => TRUE,
'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",
'field_types' => array(
'textfield',
'textarea',
),
'custom_error' => TRUE,
'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'),
),
'plain_text' => array(
'name' => "Plain text (disallow tags)",
'field_types' => array(
'textfield',
'textarea',
),
'custom_error' => TRUE,
'description' => t("Verifies that user-entered data doesn't contain HTML tags"),
),
'must_be_empty' => array(
'name' => "Must be empty",
'field_types' => array(
'textfield',
),
'custom_error' => TRUE,
'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",
'field_types' => array(
'textfield',
'textarea',
),
'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"),
),
'select_min' => array(
'name' => "Minimum number of selections required",
'field_types' => array(
'list_integer',
'list_float',
'list_text',
),
'custom_error' => TRUE,
'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 list field'),
),
'select_max' => array(
'name' => "Maximum number of selections allowed",
'field_types' => array(
'list_integer',
'list_float',
'list_text',
),
'custom_error' => TRUE,
'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 list field'),
),
'select_exact' => array(
'name' => "Exact number of selections required",
'field_types' => array(
'list_integer',
'list_float',
'list_text',
),
'custom_error' => TRUE,
'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 list field'),
),
'unique' => array(
'name' => "Unique values",
'field_types' => array(
'textfield',
),
'custom_error' => TRUE,
'custom_data' => array(
'label' => t('Scope of unique values'),
'description' => t('Specify the scope of Unique values, support: global, entity, bundle.'),
),
'description' => t('Verifies that all values are unique in current entity or bundle.'),
),
'match_another_field' => array(
'name' => "Must match another field",
'field_types' => array(
'textfield',
),
'custom_error' => TRUE,
'custom_data' => array(
'label' => t('Arguments of another field'),
'description' => t('Specify the arguments of another field, support: entity_type, field_name, bundle, column, is_property. for example,entity_type=node&bundle=article&column=title&is_property=TRUE, entity_type=user&column=name&is_property=TRUE.') . t('It also support argument "reverse", which means must not match the field if you set this argument.'),
),
'description' => t("Validates that user-entered data matches another field or entity property"),
),
'specific_value' => array(
'name' => "Specific value(s)",
'field_types' => array(
'textfield',
),
'custom_error' => TRUE,
'custom_data' => array(
'label' => t('(Key) value'),
'description' => t('Specify the specific value(s) you want the field to contain. Separate multiple options by a comma. For fields that have keys, use the key value instead.'),
),
'description' => t('Verifies that the specified field contains a defined value'),
),
'oneofseveral' => array(
'name' => "Require at least one of several fields",
'field_types' => array(
'textfield',
'textarea',
),
'custom_error' => TRUE,
'custom_data' => array(
'label' => t('group name'),
'description' => t('Specify the group name for those fields, it should be the same across those fields. Validation rules with the same group name work together.'),
),
'description' => t('Forces the user to specify / select at least one of several fields'),
),
'equal_values' => array(
'name' => "Equal values on multiple fields",
'field_types' => array(
'textfield',
),
'custom_error' => TRUE,
'custom_data' => array(
'label' => t('group name'),
'description' => t('Specify the group name for those fields, it should be the same across those fields. Validation rules with the same group name work together.'),
),
'description' => t('Verifies that all specified fields contain equal values'),
),
'unique_values' => array(
'name' => "Unique values on multiple fields",
'field_types' => array(
'textfield',
),
'custom_error' => TRUE,
'custom_data' => array(
'label' => t('group name'),
'description' => t('Specify the group name for those fields, it should be the same across those fields. Validation rules with the same group name work together.'),
),
'description' => t('Verifies that all specified fields contain unique values'),
),
'custom' => array(
'name' => "Custom PHP function",
'field_types' => array(
'textfield',
),
'custom_error' => TRUE,
'custom_data' => array(
'label' => t('Function name'),
'description' => t('Specify the custom PHP function name for this field. It contains one argument, $variables, for example, mymodule_validate_myfield($variables). Then you could enter its name at here: mymodule_validate_myfield'),
),
'description' => t('Validate current field using custom PHP function'),
),
);
}