Expand my Community achievements bar.

Validate a Negative Number

Avatar

Former Community Member
I am creating a form where there is a field to enter a discount. I want to make sure that number is always negative.



I tried using the display pattern $-z,zz9.99 and then set the validation pattern to the same thing but it isn't working. I also tried using the () version too.



I need it to work in both of these scenarios:

1. person enters -15 and it shows as -$15.00 or $-15.00

2. person enters 15 and it shows as -$15.00 or $-15.00



Using the display pattern above gives me this:

1. -$-15.00

2. $-15.00 but doesn't recognize it as a negative number in calculations.



Any help would be great!
1 Reply

Avatar

Former Community Member
I ended up solving this on my own and actually made it a more advanced field by being able to offer discounts in dollar amounts and percentages.



I ended up creating two extra fields where the user enters a discount amount and then checks a box to say whether it is a $ or %. Then I calculate the the discount using this script:



if (form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue eq null) then

null

else

if (form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue > 0 and form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountType.Type.rawValue eq 0) then

form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue * -1

else

if (form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue < 0 and form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountType.Type.rawValue eq 0) then

form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue

else

if(form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue > 0 and form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountType.Type.rawValue eq 1) then

form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row10.Subtotal.rawValue * (form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue * -0.01)

else

form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row10.Subtotal.rawValue * (form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue * 0.01)

endif

endif

endif

endif



Works perfectly!