3

I came across this multi-list field restrictions to limit range(selection) using regex. I got few references to add basic validations. Both work fine.

Ref1: ^({[^}]+}\|?){0,5}$
http://www.benramey.com/2012/06/12/limit-selected-items-on-sitecore-multilist-field/

Ref2: ^.{38,116}$
https://community.sitecore.net/technical_blogs/b/sitecorejohn_blog/posts/repost-validate-a-sitecore-checklist-multilist-treelist-or-treelistex-field

I'm looking to add regex which makes the user to select even no. items only.

Did anyone come across regex to handle custom validation at field level like this? I have added a custom field level validation rule in normal, but looking if there is any regex to handle this scenario. (Sitecore 8.2u3)

2

You can pretty much reuse the first regex, just instead of saying that you need 0-5 guids, you should say that you need 0 or more groups of 2 guids:

^({[^}]+}[|]{[^}]+}[|]?)*$

So in fact you use regex which says:

I want

  • a guid {[^}]+}
  • a pipe |
  • and another guid {[^}]+}
  • then maybe pipe |?

Everything is wrapped with ( and )* so you say that you want 0 or more of those groups above (change * to + if you need at least 2 guids to be selected.

And ^ and $ chars are at the beginning and at the end to make sure nothing is before or after.

You need to remember that this regex will not help you if your user starts playing with raw value of the field and enter value with is not pipe delimited guid list.

  • @SivaSankar missing square brackets added. All tested and works as expected now – Marek Musielak Jul 27 '17 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.