{"record":{"id":"e32c3879864da806","repo":"validatorjs/validator.js","slug":"invalid-locale-locale-e32c38","errorCode":null,"errorMessage":"Invalid locale '${locale}'","messagePattern":"Invalid locale '(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/isIdentityCard.js","lineNumber":446,"sourceCode":"\nexport default function isIdentityCard(str, locale) {\n  assertString(str);\n  if (locale in validators) {\n    return validators[locale](str);\n  } else if (locale === 'any') {\n    for (const key in validators) {\n      // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes\n      // istanbul ignore else\n      if (validators.hasOwnProperty(key)) {\n        const validator = validators[key];\n        if (validator(str)) {\n          return true;\n        }\n      }\n    }\n    return false;\n  }\n  throw new Error(`Invalid locale '${locale}'`);\n}\n","sourceCodeStart":428,"sourceCodeEnd":448,"githubUrl":"https://github.com/validatorjs/validator.js/blob/a79ff980ab14257e795332989e497bdff3218e87/src/lib/isIdentityCard.js#L428-L448","documentation":"isIdentityCard(str, locale) validates national identity-card numbers using regexes/validators keyed by locale string (e.g. 'he-IL', 'zh-CN', 'ES'). An unsupported locale key throws this error so callers do not mistake a config error for an invalid card number.","triggerScenarios":"isIdentityCard(id, 'IL') instead of 'he-IL'; isIdentityCard(id) with locale explicitly passed as undefined; locale keys removed between validator.js versions.","commonSituations":"Guessing country codes instead of using the documented locale keys; dynamic country from user profile not mapped to library keys; upgrading validator.js and a locale key changes.","solutions":["Use exact locale keys from the identityCard table in src/lib/isIdentityCard.js or the README","Map ISO country codes to validator locale keys in a lookup table","Guard with try/catch and treat unknown locale as 'unsupported' rather than 'invalid id'","Verify the key exists in the version you installed (keys differ across versions)"],"exampleFix":"// before\nvalidator.isIdentityCard(idNumber, 'IL'); // throws\n// after\nvalidator.isIdentityCard(idNumber, 'he-IL');","handlingStrategy":"validation","validationCode":"const ID_LOCALES = ['ES','he-IL','ar-TN','zh-CN','zh-TW','th-TH','LK','ko-KR','PL','FA-IR','TR','NG','ID','MY','PK','fr-LU','DE','MX'];\nif (!ID_LOCALES.includes(locale)) throw new TypeError(`Unsupported identity-card locale: ${locale}`);","typeGuard":"const isIdCardLocale = (loc) => typeof loc === 'string' && ID_LOCALES.includes(loc);","tryCatchPattern":"let ok;\ntry { ok = validator.isIdentityCard(id, locale); }\ncatch (e) { if (/^Invalid locale/.test(e.message)) { return { valid: null, reason: 'unsupported-locale' }; } throw e; }","preventionTips":["Map country metadata to exact validator keys ('he-IL', not 'IL')","Distinguish 'unsupported locale' from 'invalid id' in your API responses","Pin and test the validator version so key sets are stable","Check src/lib/isIdentityCard.js for the exact keys in your version"],"tags":["validation","locale","identity-card"],"backgroundTag":"invalid-locale","analyzedSha":"a79ff980ab14257e795332989e497bdff3218e87","analyzedAt":"2026-08-31T21:42:31.416Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}