Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeff 74 posts 346 karma points
    Apr 19, 2016 @ 14:55
    Jeff
    0

    Validating an optional field

    Hi,

    Is there a way to apply a RegEx validation to an optional field? As whenever I apply the RegEx I can't then leave the field blank.

    Thanks

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 20, 2016 @ 05:28
    Jan Skovgaard
    0

    Hi Jeff

    When you create a document type there is this "validation" textarea where you can enter a regex for validating the content of the field. However I suspect it will only work on textstring and textareas - I have not really been using this feature all that much my self.

    But if I understand you correctly this is where you can do it without having to resort to building your own custom property editor - There even is a "search for regular expression" option build in :)

    If you need to do something more advanced than that then perhaps you should consider building a custom property editor.

    Hope this helps.

    /Jan

  • Jeff 74 posts 346 karma points
    Apr 20, 2016 @ 07:29
    Jeff
    0

    Hi Jan,

    I can enter in a RegEx which validates in this case an email address, however once I add the RegEx I can't then leave the email address blank when populating the CMS with data.

    I was wondering if there was a easy way to only have the RegEx take effect if an email address was entered and not if left blank?

    Thanks

  • Tom Steer 161 posts 596 karma points
    Apr 20, 2016 @ 08:07
    Tom Steer
    2

    Hi Jeff,

    Does changing the regex to match an empty string or an email address work?

    Thanks,

    Tom

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 20, 2016 @ 11:49
    Jan Skovgaard
    100

    Hi Jeff

    What does your current regex expression look like?

    I'm no regex guru myself but according to stackoverlow this should work

    (^$|^.*@.*\..*$)
    

    You can see the full post here http://stackoverflow.com/questions/5063977/regex-empty-string-or-email

    Does this help?

    /Jan

  • Jeff 74 posts 346 karma points
    Apr 21, 2016 @ 07:53
    Jeff
    0

    Hi Jan,

    I have tried the suggestion from the StackOverflow question and it appears to work.

    Thank you for your help, Jeff

Please Sign in or register to post replies

Write your reply to:

Draft