Hi, I wrote a regex and implemented it into the editable:
Since my regex contained the pipe character, I changed the separator to # as per the document.
The regex wasn't working so I did further research and found the function that handles the regex in functions.php on line 2584:
To test further, I recreated that function within <cms:php> on my front-end code to test the regex:
Using the <cms:php> test and changing the $field to a number that is 0-24 or within results in a match and works as expected, but I can't get the editable to properly validate the regex. Any help appreciated, thank you.
- Code: Select all
<cms:editable name='count' label='Count' desc='must be number that is or within range of 0-24' type='text' required='1' validator='regex=/^([0-9]|1\d|20|2[1-4])$/' separator='#' validator_msg='regex=Number must be between 0 and 24' />
Since my regex contained the pipe character, I changed the separator to # as per the document.
- the pipe character appears within the regular expression itself, thus that validator cannot be combined with any other using a pipe.
The regex wasn't working so I did further research and found the function that handles the regex in functions.php on line 2584:
- Code: Select all
static function validate_regex( $field, $args ){
if( !preg_match(trim($args), trim($field->get_data())) ){
return KFuncs::raise_error( "Does not match pattern" );
}
}
To test further, I recreated that function within <cms:php> on my front-end code to test the regex:
- Code: Select all
<cms:php>
$args = "/^([0-9]|1\d|20|2[1-4])$/"; // validates a number that is or within range of 0-24
$field = "24"; // changing value to number that is or between 0 and 24 results in a match.
if( !preg_match(trim($args), trim($field)) ){
echo "no match";
} else {
echo "match";
}
</cms:php>
Using the <cms:php> test and changing the $field to a number that is 0-24 or within results in a match and works as expected, but I can't get the editable to properly validate the regex. Any help appreciated, thank you.