{"record":{"id":"969caa6d04ed96c2","repo":"validatorjs/validator.js","slug":"invalid-locale-locale-969caa","errorCode":null,"errorMessage":"Invalid locale '${locale}'","messagePattern":"Invalid locale '(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/isLicensePlate.js","lineNumber":39,"sourceCode":"    /^[A-HJ-PR-UW-Z]{3} ?[\\d]{2}[A-HJ-PR-UW-Z1-9]$|(^[A-ZÅÄÖ ]{2,7}$)/.test(str.trim()),\r\n  'en-PK': str => /(^[A-Z]{2}((\\s|-){0,1})[0-9]{3,4}((\\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{3}((\\s|-){0,1})[0-9]{3,4}((\\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{4}((\\s|-){0,1})[0-9]{3,4}((\\s|-)[0-9]{2}){0,1}$)|(^[A-Z]((\\s|-){0,1})[0-9]{4}((\\s|-)[0-9]{2}){0,1}$)/.test(str.trim()),\r\n};\r\n\r\nexport default function isLicensePlate(str, locale) {\r\n  assertString(str);\r\n  if (locale in validators) {\r\n    return validators[locale](str);\r\n  } else if (locale === 'any') {\r\n    for (const key in validators) {\r\n      /* eslint guard-for-in: 0 */\r\n      const validator = validators[key];\r\n      if (validator(str)) {\r\n        return true;\r\n      }\r\n    }\r\n    return false;\r\n  }\r\n  throw new Error(`Invalid locale '${locale}'`);\r\n}\r\n","sourceCodeStart":21,"sourceCodeEnd":41,"githubUrl":"https://github.com/validatorjs/validator.js/blob/a79ff980ab14257e795332989e497bdff3218e87/src/lib/isLicensePlate.js#L21-L41","documentation":"isLicensePlate(str, locale) checks vehicle license plates against locale-specific regexes (e.g. 'de-DE', 'pt-PT', 'any' to accept any supported plate). Unknown locale keys throw this error to distinguish configuration mistakes from invalid plates.","triggerScenarios":"isLicensePlate('B-AB 1234', 'DE') instead of 'de-DE'; locale passed as undefined from an unbound variable; using a country name string instead of the locale key.","commonSituations":"Mapping vehicle-registration data (ISO country) directly to the validator without translation; stale locale key after a validator.js upgrade; typo in a hard-coded key.","solutions":["Use documented keys like 'de-DE', 'pt-PT', or 'any'","Translate ISO country codes to validator keys before calling","Catch the error and return an 'unknown locale' business error instead of 'invalid plate'","Check src/lib/isLicensePlate.js for the exact key set in your installed version"],"exampleFix":"// before\nvalidator.isLicensePlate(plate, 'DE'); // throws\n// after\nvalidator.isLicensePlate(plate, 'de-DE');","handlingStrategy":"validation","validationCode":"const PLATE_LOCALES = ['de-DE','de-LI','pt-PT','fi-FI','sv-SE','sq-AL','cs-CZ','es-AR','br-PR','EC','any'];\nif (!PLATE_LOCALES.includes(locale)) throw new TypeError(`Unsupported license-plate locale: ${locale}`);","typeGuard":"const isPlateLocale = (loc) => typeof loc === 'string' && PLATE_LOCALES.includes(loc);","tryCatchPattern":"let ok;\ntry { ok = validator.isLicensePlate(plate, locale); }\ncatch (e) { if (/^Invalid locale/.test(e.message)) { return { valid: null, reason: 'unsupported-locale' }; } throw e; }","preventionTips":["Use documented keys like 'de-DE' or 'any', not ISO country codes","Build one country->locale mapping table in your codebase","Re-check supported keys after validator.js upgrades","Return a distinct business error for unsupported regions"],"tags":["validation","locale","license-plate"],"backgroundTag":"invalid-locale","analyzedSha":"a79ff980ab14257e795332989e497bdff3218e87","analyzedAt":"2026-08-31T21:42:31.416Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}