How to I validate a form field to 1 decimal place?

In this example, we are validating a decimal field that starts with 2 digits to 1 decimal place. The valid range is 10.1 to 15.4

Step 1 - Drag in a decimal field from the left and enter a Unique Field Name.


Step 2 -
In the Validations tab, create the invalid range for the in-spec values. E.g. the field is in-spec between 10.9 and 15.5.

(data["decimal"]<=10.9)||(data["decimal"]>=15.5)



Step 3 -
Create the validation for 1 decimal place

data["decimal"]=~"^\\d\\d\\.[0-9]{1}$"

Note:

  • ^ asserts the start of the string.
  • \\d\\d matches exactly two digits.
  • \\. matches a literal period (decimal point).
  • [0-9]{1} matches exactly one digit after the decimal point.
  • $ asserts the end of the string.

Examples of valid strings:

  • 12.3
  • 45.7

Examples of invalid strings:

  • 123.4 (has three digits before the period)
  • 12.34 (has two digits after the period)
  • 1.5 (has only one digit before the period)


Step 4 -
Invalidate everything outside of the valid range by inputting 1==1.

1==1

 

Other examples with decimal places (step 3):

1. Validate values 0.09 to 0.13
data["decimal"]=~"^0\.(09|1[0-2]|13)$"

The regex pattern ^0\.(09|1[0-2]|13)$ validates a string with the following conditions:

  • ^ asserts the start of the string.
  • 0\. ensures that the string starts with 0. (i.e., the number zero followed by a decimal point).
  • (09|1[0-2]|13) matches one of the following:
    • 09: The exact number "09".
    • 1[0-2]: Matches numbers from "10" to "12" (the [0-2] ensures that only 0, 1, or 2 can follow the "1").
    • 13: The exact number "13".
  • $ asserts the end of the string.

In summary, this pattern is validating numbers that start with "0." followed by one of these specific values: "09", "10", "11", "12", or "13".

Examples of valid strings:

  • 0.09
  • 0.10
  • 0.11
  • 0.12
  • 0.13

Examples of invalid strings:

  • 0.08 (not in the allowed range)
  • 0.14 (not in the allowed range)
  • 1.09 (does not start with "0.")