{"record":{"id":"8c910dfdaea59702","repo":"Semantic-Org/Semantic-UI","slug":"name-must-be-a-valid-credit-card-number","errorCode":null,"errorMessage":"{name} must be a valid credit card number","messagePattern":"(.+?) must be a valid credit card number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/definitions/behaviors/form.js","lineNumber":1276,"sourceCode":"    regExp               : '{name} is not formatted correctly',\n    integer              : '{name} must be an integer',\n    decimal              : '{name} must be a decimal number',\n    number               : '{name} must be set to a number',\n    is                   : '{name} must be \"{ruleValue}\"',\n    isExactly            : '{name} must be exactly \"{ruleValue}\"',\n    not                  : '{name} cannot be set to \"{ruleValue}\"',\n    notExactly           : '{name} cannot be set to exactly \"{ruleValue}\"',\n    contain              : '{name} must contain \"{ruleValue}\"',\n    containExactly       : '{name} must contain exactly \"{ruleValue}\"',\n    doesntContain        : '{name} cannot contain  \"{ruleValue}\"',\n    doesntContainExactly : '{name} cannot contain exactly \"{ruleValue}\"',\n    minLength            : '{name} must be at least {ruleValue} characters',\n    length               : '{name} must be at least {ruleValue} characters',\n    exactLength          : '{name} must be exactly {ruleValue} characters',\n    maxLength            : '{name} cannot be longer than {ruleValue} characters',\n    match                : '{name} must match {ruleValue} field',\n    different            : '{name} must have a different value than {ruleValue} field',\n    creditCard           : '{name} must be a valid credit card number',\n    minCount             : '{name} must have at least {ruleValue} choices',\n    exactCount           : '{name} must have exactly {ruleValue} choices',\n    maxCount             : '{name} must have {ruleValue} or less choices'\n  },\n\n  selector : {\n    checkbox   : 'input[type=\"checkbox\"], input[type=\"radio\"]',\n    clear      : '.clear',\n    field      : 'input, textarea, select',\n    group      : '.field',\n    input      : 'input',\n    message    : '.error.message',\n    prompt     : '.prompt.label',\n    radio      : 'input[type=\"radio\"]',\n    reset      : '.reset:not([type=\"reset\"])',\n    submit     : '.submit:not([type=\"submit\"])',\n    uiCheckbox : '.ui.checkbox',\n    uiDropdown : '.ui.dropdown'","sourceCodeStart":1258,"sourceCodeEnd":1294,"githubUrl":"https://github.com/Semantic-Org/Semantic-UI/blob/597843ab84d565cccfd8fd7719416350ae73e734/src/definitions/behaviors/form.js#L1258-L1294","documentation":"Default prompt for the Semantic UI Form `creditCard` rule (settings.rules.creditCard, form.js:1566). Validates the number against per-brand pattern+length (visa/amex/mastercard/discover/unionPay/jcb/maestro/dinersClub/laser/visaElectron), optionally restricted to a comma-separated `{ruleValue}` list of brands; dashes are stripped; UnionPay skips Luhn, all others require a passing Luhn checksum (form.js:1656-1670). Empty/non-string input returns undefined (falsy) → prompt shown.","triggerScenarios":"`{type:'creditCard'}` with a mistyped number, a number failing Luhn, or `{type:'creditCard[visa]'}` with an AmEx number. Empty input also triggers it.","commonSituations":"Users typing spaces/dashes (only dashes are stripped, not spaces), expired test numbers, brands outside the supported set, or requiring a brand the user is not using.","solutions":["Enter a valid card number (Luhn-valid) for an allowed brand.","Strip spaces (not just dashes) before validation: `value = value.replace(/[\\s-]/g,'')`.","If restricting brands, ensure the `{ruleValue}` list includes the user's brand.","Pair with `empty` if optional, and add a custom `prompt`."],"exampleFix":"// before - spaces not stripped, Luhn fails\nrules: [{ type: 'creditCard' }]\n\n// after - normalize spaces, restrict brands, friendly prompt\n// pre-submit: input.value = input.value.replace(/[\\s-]/g, '');\nrules: [{ type: 'creditCard[visa,mastercard]', prompt: 'Enter a valid Visa or Mastercard number' }]","handlingStrategy":"validation","validationCode":"function luhn(num) {\n  let sum = 0, alt = 0; num = num.replace(/[\\s-]/g, '');\n  if (!/^\\d+$/.test(num)) return false;\n  for (let i = num.length - 1; i >= 0; i--) { sum += [0,2,4,6,8,1,3,5,7,9][alt][parseInt(num[i],10)] ^ alt; alt ^= 1; }\n  return sum % 10 === 0 && sum > 0;\n}\nif (!luhn($field.val())) { /* warn */ }","typeGuard":"const isDigitsOnly = (v) => /^\\d+$/.test(String(v).replace(/[\\s-]/g, ''));","tryCatchPattern":null,"preventionTips":["Strip spaces AND dashes before validation (the rule only strips dashes).","If restricting brands, list all brands you accept in the ruleValue.","Pair with empty if the field is optional; never store the validated number client-side."],"tags":["semantic-ui","form-validation","credit-card","luhn","client-side"],"backgroundTag":null,"analyzedSha":"597843ab84d565cccfd8fd7719416350ae73e734","analyzedAt":"2026-08-13T01:44:23.827Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}