{"record":{"id":"039168db26963f8b","repo":"validatorjs/validator.js","slug":"invalid-locale-options-locale","errorCode":null,"errorMessage":"Invalid locale '${options.locale}'","messagePattern":"Invalid locale '(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/isDecimal.js","lineNumber":25,"sourceCode":"  const regExp = new RegExp(`^[-+]?([0-9]+)?(\\\\${decimal[options.locale]}[0-9]{${options.decimal_digits}})${options.force_decimal ? '' : '?'}$`);\n  return regExp;\n}\n\nconst default_decimal_options = {\n  force_decimal: false,\n  decimal_digits: '1,',\n  locale: 'en-US',\n};\n\nconst blacklist = ['', '-', '+'];\n\nexport default function isDecimal(str, options) {\n  assertString(str);\n  options = merge(options, default_decimal_options);\n  if (options.locale in decimal) {\n    return !includes(blacklist, str.replace(/ /g, '')) && decimalRegExp(options).test(str);\n  }\n  throw new Error(`Invalid locale '${options.locale}'`);\n}\n","sourceCodeStart":7,"sourceCodeEnd":27,"githubUrl":"https://github.com/validatorjs/validator.js/blob/a79ff980ab14257e795332989e497bdff3218e87/src/lib/isDecimal.js#L7-L27","documentation":"isDecimal(str, options) validates decimal numbers using locale-specific formats; options.locale must be a key in the decimal locales table (default 'en-US'). If the provided locale is not in that table the function throws instead of returning false.","triggerScenarios":"isDecimal('12.34', { locale: 'en' }), isDecimal(x, { locale: undefined }) after merging options that overwrote the default, or passing locale names like 'pt' rather than keys such as 'pt-BR'.","commonSituations":"Passing an options object missing locale so a later merge leaves undefined; reusing Intl locale tags ('en-GB' is valid but 'en' is not); version changes to the supported locale set.","solutions":["Use a supported key such as 'en-US' (the default) or another key from the decimal locales table in src/lib/isDecimal.js","Ensure the locale field is actually present in the options object (not clobbered by a merge with undefined)","Wrap the call and fall back to default options on invalid locale","Print the resolved options.locale to detect undefined values"],"exampleFix":"// before\nvalidator.isDecimal(price, { locale: 'en' }); // throws\n// after\nvalidator.isDecimal(price, { locale: 'en-US' });","handlingStrategy":"validation","validationCode":"const DECIMAL_LOCALES = ['en-US','en-ZA','en-AU','en-HK','en-IN','fr-FR','de-DE','pt-BR','es-ES','ar-AE','ar-EG','ar-JO','ar-KW','ar-LB','ar-SA','ar-TN','bg-BG','cs-CZ','da-DK','el-GR','en-CA','en-GB','en-IE','en-KE','en-MT','en-NG','en-NZ','en-PK','en-RW','en-SG','en-TZ','en-UG','zh-CN','zh-HK','fa-IR','gu-IN','hi-IN','id-ID','it-IT','kk-KZ','ko-KR','ja-JP','ms-MY','nb-NO','nl-NL','pl-PL','ru-RU','sl-SI','sr-RS','sv-SE','tk-TM','tr-TR','uk-UA','vi-VN'];\nconst locale = DECIMAL_LOCALES.includes(opts.locale) ? opts.locale : 'en-US';\nvalidator.isDecimal(str, { ...opts, locale });","typeGuard":"const isValidDecimalLocale = (loc) => typeof loc === 'string' && DECIMAL_LOCALES.includes(loc);","tryCatchPattern":"let ok;\ntry { ok = validator.isDecimal(str, options); }\ncatch (e) { if (/^Invalid locale/.test(e.message)) { ok = validator.isDecimal(str, { locale: 'en-US', decimal_digits: '1,', force_decimal: false }); } else { throw e; } }","preventionTips":["Never build options objects that can set locale to undefined","Use the library default ('en-US') unless a supported key is confirmed","Translate Intl locale tags to validator keys explicitly","Cover your decimal options path with a unit test"],"tags":["validation","locale","options"],"backgroundTag":"invalid-locale","analyzedSha":"a79ff980ab14257e795332989e497bdff3218e87","analyzedAt":"2026-08-31T21:42:31.416Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}