Skip to content

fix(isCreditCard): fix mastercard prefix bug for short strings (#2717)#2743

Open
dweep-js wants to merge 1 commit into
validatorjs:masterfrom
dweep-js:ismastercard-error
Open

fix(isCreditCard): fix mastercard prefix bug for short strings (#2717)#2743
dweep-js wants to merge 1 commit into
validatorjs:masterfrom
dweep-js:ismastercard-error

Conversation

@dweep-js

@dweep-js dweep-js commented Jun 8, 2026

Copy link
Copy Markdown

feat(isCreditCard): fix mastercard prefix bug for short strings

Wrapped the mastercard regular expression options in a non-capturing group (?: ... ). This ensures that the start (^) and end ($) anchors apply to both parts of the OR (|) logic, preventing short strings like '5108' from falsely validating. Added a corresponding test case to test/validators.test.js.

References: Closes #2717

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

@dweep-js dweep-js closed this Jun 8, 2026
@dweep-js dweep-js force-pushed the ismastercard-error branch from 0a19154 to 7fdc788 Compare June 8, 2026 16:35
@dweep-js dweep-js reopened this Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isCreditCard: Mastercard regex anchoring bug accepts 4-digit and partial strings

1 participant