Skip to main content
The Iranian Legal ID (شناسه ملی حقوقی) is an 11-digit identifier for companies and legal entities, with its own check-digit algorithm distinct from the personal National ID.

Function

Algorithm

  1. Falsy input → undefined.
  2. Stringify; length must be ≥ 11.
  3. Reject if parseInt(legalId) === 0.
  4. Reject if the middle 6 digits (slice(3, 9)) are all zero.
  5. Compute check digit with coefficient vector [29, 27, 23, 19, 17] (cycled per period of 5):

Pitfalls

  • Length check is < 11, not === 11. Inputs longer than 11 chars are accepted; the algorithm slices fixed indices, so longer strings can still validate. If you need strict 11-digit input, check String(input).length === 11 separately.
  • Persian/Arabic digit input is not normalized. parseInt("۱۰۳۸۰۲۸۴۷۹۰") is NaN. Run autoConvertDigitsToEN first.
  • Return type is boolean | undefined — use === true, not truthy.
  • For personal IDs (10 digits, different algorithm), use verifyIranianNationalId.

Source

src/modules/legalId/index.ts · Tests: test/verifyIranianLegalId.spec.ts