Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hey Folks,

I am trying to use regex for some validation. I am having problems where the '(|)' syntax seems to be failing.
I went so far as to copy the example out of the documentation and it in fact fails to recognize 'cat' or 'CAT' :o
when I try and save data on the backend.

This is the regex:
Code: Select all
/(cat|dog)$/i

I made an attempt eliding '$' in case some how white space was the issue. It still gave me an error message.

I know this seems like an obvious one, but I figured the release might be recent enough, it just wasn't
noticed yet. I have changed core code, but only in relation to get_gravatar so that it defaults to an
identicon. It's hard to believe that is in anyway related.

I am using:

k_cms_version: 1.4.5
k_cms_build: 20150707
Hi,

The problem is that the pipe (|) character used within the regex is clashing with the default separator between multiple validators e.g. consider the following where we are combining two validators (regex and min_len)-
Code: Select all
<cms:editable 
    ..   
    validator='regex:/(cat|dog)$/i | min_len:14'

As you can make out, the pipe '|' now becomes ambiguous.

The solution (as discussed in the docs at http://docs.couchcms.com/tags-reference ... _separator) is to declare and use a new separator as follows -
Code: Select all
<cms:editable 
    ..
    separator='#'
    validator='regex:/(cat|dog)$/i # min_len:14'


So, to resolve your issue please add separator='#' to the region's definition and the regex should work as expected.

Hope it helps.
Another Doh! I read the entire docs word for word initially, but that was months ago.
Very much, "My Bad!" I love CouchCMS. :D
3 posts Page 1 of 1