Conditional Validation for URL

Topics: Feature requests, General, Troubleshooting
Apr 26, 2011 at 6:16 AM

When adding a regular field, we have the opportunity to add Field Validation as a Regular Expression.


I have a Data Item that should be able to accept blank (empty) or a URL. This data contains fields with

  • a C1 image
  • a C1 Page Link
  • an external link ( link ( with validation )

I need to be able to allow the external link to be blank or contain a URL. The URL Regex would like something like "http[s]?://[a-z][a-z0-9-_]{2,256}..." but if I have this as a RexEx, it will deny "blank" entries. Is this possible? I don't think a RegEx alone can do this (although, with RegEx you never know... those things can be tricky)

Can C1 have regEx validation only on fields with data (non-blank)? Is this a good idea for a feature request?

Am I missing something obvious?

Apr 26, 2011 at 9:09 AM

The RegEx validator that ships with Composite C1 will match against the regex - there is no 'either empty string or regex match' option. But I have yet to see a rule that could not be expressed as a regex, and I guess there would be a rule for 'empty string or url' - you can get some inspiration here:

You can also add your own validator to Composite C1 and use that instead of the build in regex validator. Let me know if you would like more info on how to extend this area.

Apr 26, 2011 at 9:35 AM

I'd LOVE some more information on how to add my own custom validator!!

Apr 26, 2011 at 9:37 AM
atomiton wrote:

I'd LOVE some more information on how to add my own custom validator!!

Check this article How to add custom validation?

Apr 26, 2011 at 11:14 AM

Thanks! That article was actually really useful. I also figured out the RegEx. Simpler than I thought... just had to think through it. For anyone who wants to know, this RegEx will match an empty string or anything with either http:// or https:// in front. You can, of course get more specific with your URL, but I'm basically just making sure users don't forget the http