{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "national-id",
  "title": "National ID",
  "description": "Validates Iranian national ID (کد ملی) numbers using the standard 10-digit checksum.",
  "registryDependencies": [
    "@persianlabsui/normalize-persian-digits"
  ],
  "files": [
    {
      "path": "registry/base/lib/national-id.ts",
      "content": "import { normalizePersianDigits } from \"@/lib/normalize-persian-digits\"\n\n/**\n * 3-digit issuance-office prefixes assigned by Iran's National Organization\n * for Civil Registration. Used only when `checkPrefix` is enabled — a code\n * whose prefix isn't in this list either predates it or was issued after it\n * was last updated, so this check trades a few false negatives for catching\n * obviously malformed-but-checksum-valid values.\n */\nconst VALID_NATIONAL_ID_PREFIXES: ReadonlySet<string> = new Set([\n  \"001\",\n  \"002\",\n  \"003\",\n  \"004\",\n  \"005\",\n  \"006\",\n  \"007\",\n  \"008\",\n  \"011\",\n  \"015\",\n  \"020\",\n  \"025\",\n  \"031\",\n  \"032\",\n  \"037\",\n  \"038\",\n  \"041\",\n  \"042\",\n  \"043\",\n  \"044\",\n  \"045\",\n  \"048\",\n  \"049\",\n  \"051\",\n  \"052\",\n  \"053\",\n  \"055\",\n  \"056\",\n  \"057\",\n  \"058\",\n  \"059\",\n  \"060\",\n  \"061\",\n  \"062\",\n  \"063\",\n  \"064\",\n  \"065\",\n  \"067\",\n  \"068\",\n  \"069\",\n  \"070\",\n  \"072\",\n  \"073\",\n  \"074\",\n  \"075\",\n  \"076\",\n  \"077\",\n  \"078\",\n  \"079\",\n  \"081\",\n  \"082\",\n  \"083\",\n  \"084\",\n  \"085\",\n  \"086\",\n  \"087\",\n  \"088\",\n  \"089\",\n  \"090\",\n  \"091\",\n  \"092\",\n  \"093\",\n  \"094\",\n  \"096\",\n  \"097\",\n  \"098\",\n  \"105\",\n  \"106\",\n  \"108\",\n  \"109\",\n  \"110\",\n  \"111\",\n  \"112\",\n  \"113\",\n  \"114\",\n  \"115\",\n  \"116\",\n  \"117\",\n  \"118\",\n  \"119\",\n  \"120\",\n  \"121\",\n  \"122\",\n  \"123\",\n  \"124\",\n  \"125\",\n  \"126\",\n  \"127\",\n  \"128\",\n  \"129\",\n  \"136\",\n  \"137\",\n  \"138\",\n  \"145\",\n  \"146\",\n  \"149\",\n  \"150\",\n  \"152\",\n  \"153\",\n  \"154\",\n  \"155\",\n  \"157\",\n  \"158\",\n  \"159\",\n  \"160\",\n  \"161\",\n  \"162\",\n  \"163\",\n  \"164\",\n  \"165\",\n  \"166\",\n  \"167\",\n  \"168\",\n  \"169\",\n  \"170\",\n  \"171\",\n  \"172\",\n  \"173\",\n  \"174\",\n  \"175\",\n  \"181\",\n  \"182\",\n  \"183\",\n  \"184\",\n  \"185\",\n  \"186\",\n  \"187\",\n  \"188\",\n  \"189\",\n  \"190\",\n  \"191\",\n  \"192\",\n  \"193\",\n  \"194\",\n  \"195\",\n  \"196\",\n  \"197\",\n  \"198\",\n  \"199\",\n  \"200\",\n  \"202\",\n  \"203\",\n  \"205\",\n  \"206\",\n  \"208\",\n  \"209\",\n  \"211\",\n  \"212\",\n  \"213\",\n  \"214\",\n  \"215\",\n  \"216\",\n  \"217\",\n  \"218\",\n  \"219\",\n  \"220\",\n  \"221\",\n  \"222\",\n  \"223\",\n  \"224\",\n  \"225\",\n  \"226\",\n  \"227\",\n  \"228\",\n  \"229\",\n  \"230\",\n  \"236\",\n  \"237\",\n  \"238\",\n  \"239\",\n  \"240\",\n  \"241\",\n  \"242\",\n  \"243\",\n  \"244\",\n  \"245\",\n  \"246\",\n  \"247\",\n  \"248\",\n  \"249\",\n  \"250\",\n  \"251\",\n  \"252\",\n  \"253\",\n  \"254\",\n  \"255\",\n  \"256\",\n  \"257\",\n  \"258\",\n  \"259\",\n  \"261\",\n  \"262\",\n  \"263\",\n  \"264\",\n  \"265\",\n  \"266\",\n  \"267\",\n  \"268\",\n  \"269\",\n  \"270\",\n  \"271\",\n  \"272\",\n  \"273\",\n  \"274\",\n  \"275\",\n  \"279\",\n  \"280\",\n  \"282\",\n  \"283\",\n  \"284\",\n  \"285\",\n  \"286\",\n  \"287\",\n  \"288\",\n  \"289\",\n  \"290\",\n  \"291\",\n  \"292\",\n  \"293\",\n  \"294\",\n  \"295\",\n  \"296\",\n  \"297\",\n  \"298\",\n  \"299\",\n  \"302\",\n  \"303\",\n  \"304\",\n  \"305\",\n  \"306\",\n  \"307\",\n  \"308\",\n  \"309\",\n  \"310\",\n  \"311\",\n  \"312\",\n  \"313\",\n  \"314\",\n  \"315\",\n  \"316\",\n  \"317\",\n  \"318\",\n  \"319\",\n  \"320\",\n  \"321\",\n  \"322\",\n  \"323\",\n  \"324\",\n  \"325\",\n  \"330\",\n  \"331\",\n  \"332\",\n  \"333\",\n  \"334\",\n  \"335\",\n  \"336\",\n  \"337\",\n  \"338\",\n  \"339\",\n  \"341\",\n  \"342\",\n  \"343\",\n  \"344\",\n  \"345\",\n  \"346\",\n  \"347\",\n  \"348\",\n  \"349\",\n  \"350\",\n  \"351\",\n  \"352\",\n  \"353\",\n  \"354\",\n  \"355\",\n  \"356\",\n  \"357\",\n  \"358\",\n  \"359\",\n  \"361\",\n  \"362\",\n  \"364\",\n  \"365\",\n  \"366\",\n  \"367\",\n  \"369\",\n  \"370\",\n  \"371\",\n  \"372\",\n  \"373\",\n  \"375\",\n  \"376\",\n  \"377\",\n  \"378\",\n  \"379\",\n  \"380\",\n  \"381\",\n  \"382\",\n  \"383\",\n  \"384\",\n  \"385\",\n  \"386\",\n  \"387\",\n  \"392\",\n  \"393\",\n  \"394\",\n  \"395\",\n  \"396\",\n  \"397\",\n  \"398\",\n  \"399\",\n  \"400\",\n  \"401\",\n  \"402\",\n  \"403\",\n  \"404\",\n  \"405\",\n  \"406\",\n  \"407\",\n  \"412\",\n  \"413\",\n  \"416\",\n  \"417\",\n  \"418\",\n  \"419\",\n  \"420\",\n  \"421\",\n  \"422\",\n  \"423\",\n  \"424\",\n  \"425\",\n  \"426\",\n  \"427\",\n  \"428\",\n  \"431\",\n  \"432\",\n  \"436\",\n  \"437\",\n  \"438\",\n  \"439\",\n  \"440\",\n  \"441\",\n  \"442\",\n  \"443\",\n  \"444\",\n  \"445\",\n  \"446\",\n  \"447\",\n  \"448\",\n  \"449\",\n  \"450\",\n  \"451\",\n  \"452\",\n  \"453\",\n  \"454\",\n  \"455\",\n  \"456\",\n  \"457\",\n  \"458\",\n  \"459\",\n  \"460\",\n  \"461\",\n  \"462\",\n  \"464\",\n  \"465\",\n  \"466\",\n  \"467\",\n  \"468\",\n  \"469\",\n  \"470\",\n  \"471\",\n  \"472\",\n  \"481\",\n  \"482\",\n  \"483\",\n  \"484\",\n  \"485\",\n  \"486\",\n  \"487\",\n  \"488\",\n  \"489\",\n  \"490\",\n  \"491\",\n  \"492\",\n  \"493\",\n  \"494\",\n  \"495\",\n  \"496\",\n  \"497\",\n  \"498\",\n  \"499\",\n  \"500\",\n  \"501\",\n  \"502\",\n  \"503\",\n  \"504\",\n  \"505\",\n  \"506\",\n  \"507\",\n  \"508\",\n  \"509\",\n  \"510\",\n  \"511\",\n  \"512\",\n  \"513\",\n  \"514\",\n  \"515\",\n  \"516\",\n  \"517\",\n  \"518\",\n  \"519\",\n  \"520\",\n  \"521\",\n  \"522\",\n  \"523\",\n  \"524\",\n  \"525\",\n  \"526\",\n  \"527\",\n  \"528\",\n  \"529\",\n  \"530\",\n  \"531\",\n  \"532\",\n  \"533\",\n  \"534\",\n  \"535\",\n  \"536\",\n  \"537\",\n  \"538\",\n  \"539\",\n  \"540\",\n  \"541\",\n  \"542\",\n  \"543\",\n  \"544\",\n  \"545\",\n  \"546\",\n  \"547\",\n  \"548\",\n  \"549\",\n  \"550\",\n  \"551\",\n  \"552\",\n  \"553\",\n  \"554\",\n  \"555\",\n  \"556\",\n  \"557\",\n  \"558\",\n  \"559\",\n  \"560\",\n  \"561\",\n  \"562\",\n  \"563\",\n  \"564\",\n  \"565\",\n  \"566\",\n  \"567\",\n  \"568\",\n  \"569\",\n  \"570\",\n  \"571\",\n  \"572\",\n  \"573\",\n  \"574\",\n  \"575\",\n  \"576\",\n  \"577\",\n  \"578\",\n  \"579\",\n  \"580\",\n  \"581\",\n  \"582\",\n  \"583\",\n  \"584\",\n  \"585\",\n  \"586\",\n  \"587\",\n  \"588\",\n  \"589\",\n  \"590\",\n  \"591\",\n  \"592\",\n  \"593\",\n  \"594\",\n  \"595\",\n  \"596\",\n  \"597\",\n  \"598\",\n  \"599\",\n  \"600\",\n  \"601\",\n  \"602\",\n  \"603\",\n  \"604\",\n  \"605\",\n  \"606\",\n  \"607\",\n  \"608\",\n  \"609\",\n  \"610\",\n  \"611\",\n  \"612\",\n  \"613\",\n  \"614\",\n  \"615\",\n  \"616\",\n  \"617\",\n  \"618\",\n  \"619\",\n  \"620\",\n  \"621\",\n  \"622\",\n  \"623\",\n  \"624\",\n  \"625\",\n  \"626\",\n  \"627\",\n  \"628\",\n  \"629\",\n  \"630\",\n  \"631\",\n  \"632\",\n  \"633\",\n  \"634\",\n  \"635\",\n  \"636\",\n  \"637\",\n  \"638\",\n  \"639\",\n  \"640\",\n  \"641\",\n  \"642\",\n  \"643\",\n  \"644\",\n  \"645\",\n  \"646\",\n  \"647\",\n  \"648\",\n  \"649\",\n  \"650\",\n  \"651\",\n  \"652\",\n  \"653\",\n  \"654\",\n  \"655\",\n  \"656\",\n  \"657\",\n  \"658\",\n  \"659\",\n  \"660\",\n  \"661\",\n  \"662\",\n  \"663\",\n  \"664\",\n  \"665\",\n  \"666\",\n  \"667\",\n  \"668\",\n  \"669\",\n  \"670\",\n  \"671\",\n  \"672\",\n  \"673\",\n  \"674\",\n  \"675\",\n  \"676\",\n  \"677\",\n  \"678\",\n  \"679\",\n  \"680\",\n  \"681\",\n  \"682\",\n  \"683\",\n  \"684\",\n  \"685\",\n  \"686\",\n  \"687\",\n  \"688\",\n  \"689\",\n  \"690\",\n  \"691\",\n  \"692\",\n  \"693\",\n  \"694\",\n  \"695\",\n  \"696\",\n  \"697\",\n  \"698\",\n  \"699\",\n  \"700\",\n  \"701\",\n  \"702\",\n  \"703\",\n  \"704\",\n  \"705\",\n  \"706\",\n  \"707\",\n  \"708\",\n  \"709\",\n  \"710\",\n  \"711\",\n  \"712\",\n  \"713\",\n  \"714\",\n  \"715\",\n  \"716\",\n  \"717\",\n  \"718\",\n  \"719\",\n  \"720\",\n  \"721\",\n  \"722\",\n  \"723\",\n  \"724\",\n  \"725\",\n  \"726\",\n  \"727\",\n  \"728\",\n  \"729\",\n  \"730\",\n  \"731\",\n  \"732\",\n  \"775\",\n  \"778\",\n  \"986\",\n])\n\nexport interface IsValidNationalIdOptions {\n  /**\n   * Also verify the first 3 digits against the known issuance-office prefix\n   * list. Rejects malformed-but-checksum-valid values, at the cost of a\n   * false negative on any prefix issued after this list was last updated —\n   * pass `false` if you'd rather skip that risk and rely on the checksum\n   * alone.\n   *\n   * @default true\n   */\n  checkPrefix?: boolean\n}\n\n/**\n * Validates an Iranian national ID (کد ملی).\n *\n * - Accepts 8-10 digit input; shorter values are zero-padded on the left,\n *   matching systems that store the code without leading zeros.\n * - Rejects an all-zero value and any repeated-digit sequence (e.g.\n *   \"1111111111\").\n * - Rejects a value whose 6 middle digits (positions 4-9) are all zero.\n * - Verifies the 10th digit against the standard weighted checksum: each of\n *   the first 9 digits is weighted by (10 - index), the weighted sum is\n *   taken mod 11, and the result must match the check digit — with the\n *   well-known edge case that a remainder under 2 expects the check digit\n *   to equal the remainder itself, rather than 11 - remainder.\n * - By default, also verifies the 3-digit prefix against known\n *   issuance-office codes (see `checkPrefix`).\n *\n * @example\n * isValidNationalId(\"0499370899\") // true\n * isValidNationalId(\"499370899\") // true — zero-padded to \"0499370899\"\n * isValidNationalId(\"۰۴۹۹۳۷۰۸۹۹\") // true — Persian digits normalized first\n * isValidNationalId(\"0000000000\") // false — all zeros\n * isValidNationalId(\"1111111111\") // false — repeated digits\n * isValidNationalId(\"0499370898\") // false — bad checksum\n */\nexport function isValidNationalId(\n  value: string | null | undefined,\n  options: IsValidNationalIdOptions = {}\n): boolean {\n  const { checkPrefix = true } = options\n  const digits = normalizePersianDigits(value ?? \"\").replace(/\\D/g, \"\")\n\n  if (digits.length < 8 || digits.length > 10) return false\n  if (Number(digits) === 0) return false\n\n  const padded = digits.padStart(10, \"0\")\n\n  if (/^(\\d)\\1{9}$/.test(padded)) return false\n  if (Number(padded.slice(3, 9)) === 0) return false\n  if (checkPrefix && !VALID_NATIONAL_ID_PREFIXES.has(padded.slice(0, 3))) {\n    return false\n  }\n\n  const check = Number(padded[9])\n  const sum = padded\n    .slice(0, 9)\n    .split(\"\")\n    .reduce((total, digit, index) => total + Number(digit) * (10 - index), 0)\n  const remainder = sum % 11\n\n  return remainder < 2 ? check === remainder : check === 11 - remainder\n}\n",
      "type": "registry:lib"
    }
  ],
  "type": "registry:lib"
}