{"record":{"id":"6294646361f68d71","repo":"validatorjs/validator.js","slug":"ignore-should-be-instance-of-a-string-or-regexp-629464","errorCode":null,"errorMessage":"ignore should be instance of a String or RegExp","messagePattern":"ignore should be instance of a String or RegExp","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/isAlphanumeric.js","lineNumber":16,"sourceCode":"import assertString from './util/assertString';\nimport { alphanumeric } from './alpha';\n\nexport default function isAlphanumeric(_str, locale = 'en-US', options = {}) {\n  assertString(_str);\n\n  let str = _str;\n  const { ignore } = options;\n\n  if (ignore) {\n    if (ignore instanceof RegExp) {\n      str = str.replace(ignore, '');\n    } else if (typeof ignore === 'string') {\n      str = str.replace(new RegExp(`[${ignore.replace(/[-[\\]{}()*+?.,\\\\^$|#\\\\s]/g, '\\\\$&')}]`, 'g'), ''); // escape regex for ignore\n    } else {\n      throw new Error('ignore should be instance of a String or RegExp');\n    }\n  }\n\n  if (locale in alphanumeric) {\n    return alphanumeric[locale].test(str);\n  }\n  throw new Error(`Invalid locale '${locale}'`);\n}\n\nexport const locales = Object.keys(alphanumeric);\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/validatorjs/validator.js/blob/a79ff980ab14257e795332989e497bdff3218e87/src/lib/isAlphanumeric.js#L1-L27","documentation":"isAlphanumeric(str, locale, ignore) shares the same `ignore` handling as isAlpha: truthy `ignore` must be a String or RegExp of characters to remove before testing. Any other type (number, array, non-RegExp object) throws this error.","triggerScenarios":"isAlphanumeric('abc123', 'en-US', 0.5), passing an array of ignored chars, or passing a cross-realm RegExp-like object.","commonSituations":"Options sourced from JSON/CLI/config where types are not guaranteed; refactors that changed ignore from string to array; script tags/objects mistakenly reused as ignore arguments.","solutions":["Coerce to string or build a RegExp before the call","Join arrays of characters into a string: chars.join('')","Type-check the value (typeof === 'string' || value instanceof RegExp) before calling","Align the call signature with the current version's docs in README"],"exampleFix":"// before\nvalidator.isAlphanumeric(id, 'en-US', ['-']); // array\n// after\nvalidator.isAlphanumeric(id, 'en-US', '-');","handlingStrategy":"type-guard","validationCode":"if (ignore != null && typeof ignore !== 'string' && !(ignore instanceof RegExp)) {\n  throw new TypeError('ignore must be a string or RegExp before calling isAlphanumeric');\n}","typeGuard":"const isIgnoreOption = (v) => v == null || typeof v === 'string' || v instanceof RegExp;","tryCatchPattern":"let result;\ntry { result = validator.isAlphanumeric(str, locale, ignore); }\ncatch (e) { if (/ignore should be/.test(e.message)) { result = validator.isAlphanumeric(str, locale); } else { throw e; } }","preventionTips":["Keep ignore as a plain string of characters","Convert arrays to strings at the config boundary","Avoid passing DOM/script objects or cross-realm RegExp clones","Document the option type in your wrapper API"],"tags":["validation","options","type-error"],"backgroundTag":"invalid-option-type","analyzedSha":"a79ff980ab14257e795332989e497bdff3218e87","analyzedAt":"2026-08-31T21:42:31.416Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}