Roman Numeral Validator

Strict mode requires the unique canonical form. Alternative mode accepts a documented additive grammar. Extended mode accepts (GROUP)remainder. Invalid strings are not assigned a fabricated decimal value.

IIII is not canonical; in alternative mode it is recognized as 4 with canonical equivalent IV. IC is invalid in both strict and alternative modes because IC is not one of the six subtractive pairs.

Validation stages

  1. Input presence
  2. Character validation
  3. Length validation (128 characters)
  4. Canonical structure against ^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$
  5. Decimal range 1–3999
  6. Round-trip: convert back and require an exact match

Valid examples include I, IV, IX, XL, XC, CD, CM, MCMXCIX, and MMMCMXCIX. Invalid canonical examples include IIII, VV, IL, IC, XM, VX, IIV, IIX, IXIX, MMMM, ABC, and 123. Some noncanonical forms have specialized uses; the validator distinguishes invalid-under-canonical-rules, recognized alternative, and unsupported or ambiguous notation.

Open the rules library