Test accepted and rejected cases
Test accepted and rejected order IDs. Then change the pattern to see a test fail.
Define the intended format
This guide uses ORD- followed by four ASCII digits. Select JavaScript, remove all flags, and use:
^ORD-[0-9]{4}$
Add positive and negative cases
- Open Unit Tests.
- Select Add unit test for each row.
- Set Assertion target to regex.
- Select the expected result in Assertion.
| Input | Criterion | Purpose |
|---|---|---|
ORD-0042 | does match | Ordinary accepted value |
ORD-9999 | does match | Four digits |
ORD-42 | does not match | Too few digits |
ORD-00000 | does not match | Too many digits |
XORD-0001 | does not match | Extra prefix |
| Empty input | does not match | Missing value |
- Open Unit test actions (⋮) and select Run tests.
- Verify that all expectations pass.
If the list hides some results, select Show all tests in Unit test actions.
Inspect a failing test
- Change
{4}to{2,4}. - Run the same tests.
- Inspect the failure for
ORD-42. - Restore
{4}. - Run the tests again.
The negative case fails because the changed pattern accepts two-digit IDs. Restoring {4} restores the required format.
Include a line-ending boundary
Without m, the JavaScript pattern rejects ORD-0042\n. Enabling m permits a match on the first line.
Here, \n represents an actual newline, rather than two typed characters.
Keep m disabled for this identifier field. A full-match comparison can also guard against a later flag change.
The classification guide shows this comparison in JavaScript.
Choose tests or multiple strings
Unit tests record expected outcomes and report whether each case passes. Multiple test strings let you explore results across separate editable inputs. A saved workspace preserves the unit tests for later changes.