{"record":{"id":"e03ddb8f661d07df","repo":"validatorjs/validator.js","slug":"invalid-locale-locale-e03ddb","errorCode":null,"errorMessage":"Invalid locale '${locale}'","messagePattern":"Invalid locale '(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/isTaxID.js","lineNumber":1301,"sourceCode":"  assertString(str);\n  // Copy TIN to avoid replacement if sanitized\n  let strcopy = str.slice(0);\n\n  if (locale in taxIdFormat) {\n    if (locale in sanitizeRegexes) {\n      strcopy = strcopy.replace(sanitizeRegexes[locale], '');\n    }\n    if (!taxIdFormat[locale].test(strcopy)) {\n      return false;\n    }\n\n    if (locale in taxIdCheck) {\n      return taxIdCheck[locale](strcopy);\n    }\n    // Fallthrough; not all locales have algorithmic checks\n    return true;\n  }\n  throw new Error(`Invalid locale '${locale}'`);\n}\n","sourceCodeStart":1283,"sourceCodeEnd":1303,"githubUrl":"https://github.com/validatorjs/validator.js/blob/a79ff980ab14257e795332989e497bdff3218e87/src/lib/isTaxID.js#L1283-L1303","documentation":"isTaxID(str, locale) validates a tax ID against locale-specific rules. The locale argument is looked up in the internal taxIdCheck map of supported locales; if the key is absent, the function throws this Error instead of returning false. It signals a programming mistake in the locale argument, not an invalid input string.","triggerScenarios":"Calling isTaxID(str, locale) with a locale string not in the supported set: misspelled names ('en_US' vs 'en-US'), unsupported countries ('us' lowercase, 'fr'), a variable that is undefined/null producing 'undefined'/'null' in the message, or a locale removed/renamed between validator versions.","commonSituations":"Hardcoding a locale from user config or an env var without checking support; passing a country code where a locale code is expected; upgrading validator.js and using a locale name that changed; dynamic locale selection from a dropdown not aligned with the library's list.","solutions":["Check the locale against the supported list documented in the README (isTaxID section) and fix the spelling/format (e.g. 'en-US', 'de-AT').","Log/inspect the actual locale value at the call site — undefined variables interpolate as 'undefined'.","Guard the call: only invoke isTaxID when the locale is in your own whitelist of supported locales, otherwise skip or use a different validator.","Pin/verify your validator.js version and confirm the locale exists in that version's src/lib/isTaxID.js taxIdCheck map."],"exampleFix":"// before\nvalidator.isTaxID(taxId, userLocale); // throws if userLocale is 'US'\n// after\nconst SUPPORTED = ['en-US', 'de-AT', 'es-ES', 'fr-FR'];\nif (SUPPORTED.includes(userLocale)) {\n  validator.isTaxID(taxId, userLocale);\n} else {\n  throw new Error(`Unsupported tax ID locale: ${userLocale}`);\n}","handlingStrategy":"validation","validationCode":"const SUPPORTED_TAX_LOCALES = ['en-US','en-CA','de-AT','de-DE','es-ES','fr-FR','gb-GB']; // per README isTaxID list\nfunction isValidTaxIdFormat(str, locale) {\n  if (typeof str !== 'string' || typeof locale !== 'string') return false;\n  return SUPPORTED_TAX_LOCALES.includes(locale) && validator.isTaxID(str, locale);\n}","typeGuard":"function isSupportedTaxLocale(locale) {\n  return typeof locale === 'string' && SUPPORTED_TAX_LOCALES.includes(locale);\n}","tryCatchPattern":"try {\n  return validator.isTaxID(str, locale);\n} catch (e) {\n  if (/^Invalid locale/.test(e.message)) {\n    console.warn(`Unsupported tax ID locale: ${locale}`);\n    return false;\n  }\n  throw e;\n}","preventionTips":["Keep a whitelist constant of locales your app supports and intersect it with the library's documented isTaxID locale list.","Never pass raw user/config values as locale without normalizing (trim, lowercase language, uppercase region, join with '-').","On validator.js upgrades, diff the taxIdCheck keys in src/lib/isTaxID.js for removed/renamed locales.","Add a unit test asserting your app's locale list only contains locales accepted by isTaxID."],"tags":["validator","locale","argument-validation","input-error"],"backgroundTag":"invalid-locale-code","analyzedSha":"a79ff980ab14257e795332989e497bdff3218e87","analyzedAt":"2026-08-31T21:42:31.416Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}