Copied to clipboard

Flag this post as spam?

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


  • Gary Stenstrom 4 posts 66 karma points
    Apr 22, 2015 @ 10:15
    Gary Stenstrom
    0

    Trying to validate field only if a value is provided otherwise allow null.

    I am new to Umbraco and am enjoyting it considerably. I am encountering a bit of a snag though and was hoping I could get some guidance ... 

    I have added a texbox to a Document type which is intended to contain an email address. It's optional, but if it IS filled out I was to apply a RegEx to validate the format of the entered email address.

    The problem I am running into is that when it's left empty it's failing validation, even though tit is not set to be "Required". I had assumed that the validation would only apply itself in the event that content was provided but it appears that that is not the case. 

    What is the work around for this situation? I am trying to do as much "out of the box" as possible before extending the system and was hoping that there would be a relatively "stock" solution to this issue.

    I appreciate your help!!

    Thanks again,

    G

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Apr 22, 2015 @ 10:46
    Jeroen Breuer
    0

    Hello,

    There isn't any real solution for this. The easiest way is probably to don't have any validation on the textbox and when you need to render it somewhere check there if it's a valid email.

    You could have a look at the uDynamic package, but I don't know how that works exactly.

    Jeroen

  • Gary Stenstrom 4 posts 66 karma points
    Apr 22, 2015 @ 18:23
    Gary Stenstrom
    102

    So I discovered an alternative. Instead of something in the system handling the empty value we can add it to the actual RegEx. So the RegEx will be valid in the event of a blank entry OR a valid email (for example) ... ^\B|[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$  ... By prepending the ... \B| ...  to the original RegEx .. [\w-\.]+@([\w-]+\.)+[\w-]{2,4} ... it says that it will be valid if the entry is empty OR a valid email.

Please Sign in or register to post replies

Write your reply to:

Draft