How to validate and differentiate between 0 and empty in Flow?
In OFS Flow validations, OFS will read 0 and empty fields as the same. This article guides you through using regex to differentiate between the two.
Example 1
- Valid if the field is = 0
- Error if the field is = empty
Step 1 — Create the decimal field
- Drag in the field from the left
- Enter a Unique Field Name

Step 2 — Open the field's validation rules
Click the Field Validation Rules tab and drag in the value field from the right, dropping it into the empty space.

Step 3 — Set the rule outcome
Click on the "Valid" word, then set the Form Status, colour, and a message if needed.
Note: The Error status will not allow the user to submit the form until the field is valid.


Step 4 — Add the empty-field rule
data["field"]=~"^$"This marks the field as an error if it's empty.

Step 5 — Add the valid-if-zero-or-more rule
data["field"]>=0This marks the field as valid if it's 0 or greater.

Example 2 — a field conditional on a Yes/No selection
- Selection Box = Yes or No
- Integer Field = numbers or can be empty
- Valid when the Selection Box field is Yes and the field is 0,
- Error when the Selection Box field is Yes and the field is empty
- Valid when the Selection Box is No and empty
Step 1 — Create the selection field
- Drag in the field from the left
- Enter a Unique Field Name
- Click the
+button and add the Yes/No values

Step 2 — Create the integer field

Step 3 — Open the field's validation rules
Drag in the value field from the right and drop it into the empty space, then click on the "Valid" word and set the Form Status, colour, and a message if needed.



Step 4 — Add the conditional error rule
(data["Selection Box"]=="Yes")&&(data["Field"]=~"^$")
- This is an error if the selection is Yes and the field is empty.

Step 5 — Add the valid-if-zero-or-more rule
data["Field"]>=0
- This is valid if the field is 0 or greater.
