Commit c9877df3 authored by Jelle Sebreghts's avatar Jelle Sebreghts
Browse files

added support for regular expressions used by webform_validation

parent 29d072ed
......@@ -193,6 +193,20 @@
return value != target.val();
}, jQuery.format('Please don\'t enter the same value again.'));
jQuery.validator.addMethod("regexMatch", function(value, element, param) {
if (this.optional(element) && value == '') {
return this.optional(element);
}
else {
var regexp = new RegExp(param);
if(regexp.test(value)){
return true;
}
return false;
}
}, jQuery.format('The value does not match the expected format.'));
// EAN code
jQuery.validator.addMethod("validEAN", function(value, element, param) {
if (this.optional(element) && value == '') {
......
......@@ -178,6 +178,13 @@ function clientside_validation_webform_after_build(&$form, &$form_state) {
_clientside_validation_set_ean('submitted[' . $component['form_key'] . ']', $component['name'], $js_rules, $message);
}
break;
case 'regex':
foreach ($webform_validation_rule['components'] as $component) {
$message = $webform_validation_rule['error_message'];
$expression = $webform_validation_rule['data'];
_clientside_validation_set_regex('submitted[' . $component['form_key'] . ']', $component['name'], $js_rules, $expression, $message);
}
break;
}
}
}
......@@ -523,6 +530,16 @@ function _clientside_validation_set_ean($name, $title, &$js_rules, $message = ''
$js_rules[$name]['messages']['validEAN'] = $message;
}
/**
* Set validation rule for fields with regex validation from webform_validation
*/
function _clientside_validation_set_regex($name, $title, &$js_rules, $expression, $message = '') {
$title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
$message = empty($message) ? t('!name field is not a valid EAN number.', array('!name' => $title)) : $message;
$js_rules[$name]['regexMatch'] = $expression;
$js_rules[$name]['messages']['regexMatch'] = $message;
}
/**
* Set validation rule for file fields that must have a certain extension.
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment