How to create a case-insensitive barcode matching validation in my form?
This article outlines how to implement a validation rule in OFS-Flow that allows for case-insensitive matching of barcode values. This is particularly useful when barcode data might be entered or scanned with varying capitalisation.
Scenario
You have a field called "barcode" in your form, and you want to validate it against a barcode stored in the job metadata (e.g., jobmeta["barcode"]
). The validation should pass even if the capitalisation of the entered barcode differs from the stored barcode.
For example, if jobmeta["barcode"]
is "a123B", the following entered values should be considered valid:
- a123B
- A123B
- a123b
- A123b
Rule Configuration
Step 1 - In the barcode field, navigate to the 'Field Validation Rules' tab
Step 2 - "Mark form as Valid without message, when"
test(jobmeta["barcode"], data["barcode"], "gi") && jobmeta["barcode"].length==data["barcode"].length
-
Explanation of the formula:
test(jobmeta["barcode"], data["barcode"], "gi")
:
This function attempts to match thedata["barcode"]
(the value entered in the form) against thejobmeta["barcode"]
(the expected barcode from job metadata).- The
gi
flag stands for:g
: Global search (finds all matches rather than stopping after the first). While not strictly necessary for a direct match, it's a common flag for flexible regex.i
: Case-insensitive search. This is crucial for ignoring capitalization differences.
- The
&&
: This is a logical AND operator. Both conditions on either side of it must be true for the entire expression to be true.jobmeta["barcode"].length==data["barcode"].length
: This ensures that the length of the barcode entered in the form is exactly the same as the expected barcode from the job metadata. This prevents partial matches or accidental validity if a shorter string happens to be a case-insensitive subset of the expected barcode.
Step 3 - Add a new validation rule with the '+' icon
Step 4 - Click the 'valid' button to change to 'Invalid' and select a colourStep 5 - "Otherwise, mark form as Invalid without message, when"
1==1
This always evaluates as true, meaning any unmatched input is invalid by default.