---
title: "Example 3 - Adding/Editing Work Order (Line) Item - Validate Input Value with RegEx"
canonical: "https://help.fieldbuddy.com/space/FBDOCS/5984616474/Example+3+-+Adding%2FEditing+Work+Order+(Line)+Item+-+Validate+Input+Value+with+RegEx"
format: markdown
---
For Details check: [https://upperdeck.atlassian.net/wiki/spaces/FBDOCS/pages/5381455880](https://upperdeck.atlassian.net/wiki/spaces/FBDOCS/pages/5381455880) 

This example might not have an immediate practical use, but it can serve as a starting point for creating one.

It shows how to prevent adding or updating another expense if the Item Code doesn’t follow the expected pattern. The pattern is defined using a regular expression: `/^CC[0-9]{4}$/`.

This regular expression works as follows:

- `^` ensures the pattern starts at the beginning of the Item Code.
- `CC` requires the Item Code to start with the letters "CC".
- `[0-9]{4}` ensures that "CC" is followed by exactly 4 digits (0-9).
- `$` ensures the pattern ends immediately after the 4 digits.

For example, "CC1234" matches the pattern, but "CC123" or "XX1234" does not.

```
{
    "Id": "EXAMPLE-3",
    "Name": "Regular Expression",
    "Code__c": null,
    "Error_Message__c": "The code is incorrect.\n\nIt should start with CC followed by 4 digits.",
    "Formula__c": "",
    "SwiftFormula": {
        "params": [
            {
                "var": "${ITEM_CODE}",
                "table": "FIELDBUDDY__Work_Order_Line_Item__c",
                "field": "FIELDBUDDY__Item_Code__c"
            }
        ],
        "formula": "f=()=>{ var re= new RegExp(/^CC[0-9]{4}$/); return !(re.test('${ITEM_CODE}'));  };Boolean(f());"
    },
    "Mobile_Page__r": "Edit Work Order Other Expenses"
}
```



![image](media://272d55c9-2fea-43d9-9bb4-95f7567eb850)


```
EXAMPLE-3 Regular Expression at Edit Work Order Other Expenses
f=()=>{ var re= new RegExp(/^CC[0-9]{4}$/); return !(re.test('CC123'));  };Boolean(f());
Pass: false
ErrorMessage: The code is incorrect.

It should start with CC and follow 4 digits.
```