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.
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.
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.
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
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
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.
is working on a reply...