Classify order identifiers
Require ORD- followed by exactly four ASCII digits for an accepted identifier. This guide uses JavaScript and a strict whole-input comparison.
Describe the format
^ORD-[0-9]{4}$
Use no flags. ^ starts the match at the beginning of the input, and {4} requires four digits.
$ requires the end of the input because multiline mode is disabled.
Verify ordinary cases
| Input | Pattern finds a match? | Strict format accepted? |
|---|---|---|
ORD-0042 | Yes | Yes |
ORD-9999 | Yes | Yes |
ORD-42 | No | No |
ORD-00000 | No | No |
XORD-0001 | No | No |
ord-0042 | No | No |
| Empty input | No | No |
ORD-0042 followed by a newline | No | No |
A case-insensitive flag changes the lowercase result. A multiline flag changes how the anchors treat lines. Neither flag belongs in this particular format check.
Require the entire input
With this pattern and no flags, test() rejects the trailing newline.
An explicit full-input comparison also makes the intended contract clear:
const pattern = /^ORD-[0-9]{4}$/
function isOrderIdentifier(value) {
const match = pattern.exec(value)
return match !== null && match[0] === value
}
console.log(isOrderIdentifier('ORD-0042')) // true
console.log(isOrderIdentifier('ORD-0042\n')) // false
console.log(isOrderIdentifier('ORD-42')) // false
The comparison preserves the input exactly. It does not trim spaces or line endings before deciding. If your application trims input deliberately, verify that separate transformation too.
Use the identifier in an application
The pattern validates the text format. An order lookup is a separate operation.
For example, ORD-9999 passes this format check even if the database has no corresponding order.
The editor's does match unit-test expectation asserts that a match exists. Your application's test suite must also cover the full-input comparison used here.