I have a currency field. If a user adds the "$" sign to the currency field along with the amount, the calculated field below does not calculate properly. Is there a way to create a validation or some way, programmatically, to not accept the "$" sign?
Solved! Go to Solution.
There are a couple ways to do this.
1. You could use a validation rule on the text field:
2. Or, the validation could be set in the control's settings using regex:
The problem with these two types of field validation is that they will not fire until the user submits the form. Once they do that, the form will display all errors for the form.
so that it removes $ sign and calculates correctly regardless it's there or not
Thank you for replying. I have a few questions. Where are you placing this formula, in a rule, under formatting? I am assuming that "sourceCode" in your example is a variable? If so, why would you not use the "named" field?
I tried applying this formula under a rule, under formatting and it did not work. Perhaps I do not understand where this formula should be applied?
yes, "sourceControl" is meant a named control that holds your currency value and that appears in your validation formula.
you should use my snippet in place of your "sourceControl" reference.
so if eg. your original validation formula looks like
sourceControl < 100
it should now look like
1*replace(sourceControl,"\\$","") < 100
1. validation error at the right-most picture doesn't seem to be caused by this rule. if it was there would be an error message just like on middle one
2. your validation formula doesn't seem to be correct. validation formula has to evaluate to boolean TRUE/FALSE. your formula evaluates to a number entered in ShipmentCost field. and anything but zero is regarded as TRUE, hence you always get validation error for a number different from zero.
if you want to have a validation formula which just check for presence of $ sign, you'd better use contain() runtime function.
1. the validation error message was the same across, I just did not display it twice. I disgaree, the error message is indeed being caused by the validation.
2. "if you want to have a validation formula which just check for presence of $ sign" That is the question that I was asking. The $ sign is interfering with the calculation of the "Total" field below.
then you should apply the same to the 'Total' calculation formula (and you do not need validation rule that check $ occurence)
1*replace(ShipmentCost,"\\$","") + 1*replace(TaxCost,"\\$","")