Skip CVC validation when card number validation fails#809
Conversation
🦋 Changeset detectedLatest commit: f805ed2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| !cardValidation.isValid | ||
| ) { | ||
| return undefined; | ||
| } |
There was a problem hiding this comment.
I might be splitting hairs, and maybe overcomplicating so feel free to ignore
But I reckon when a CVC is entered that would be invalid for any card type (basically any CVC <3 digits), we should persist the invalid warning. However, if the CVC could be valid depending on the card type, that's when we should clear the warning.
On another note, would it be better to try to decouple CVC validation in the card-validator from card number validation? It feels here we are hijacking the validateCVC behaviour, instead of improving it
| return { | ||
| cvc: null, | ||
| isValid: false, | ||
| reason: "invalid_number", |
There was a problem hiding this comment.
same as my comment bellow. I wonder if CVC validation should just be decoupled from card validation.
The reason being is that conceptually the validateCVC function should return true or false only. Imo the card number being valid should be irrelevant (the brand the card number matches is a different story)
pseudo-code cvc validation suggestion:
const { brands } = validateNumber(cardNumber); // used only to check if number matches any brands
if (cvc valid for any brands) {
return true;
}
if (brands && cvc not valid for any brands) {
return false;
}
if (no brands && cvc.length < 3) {
return false;
}
return true;
a763cbe to
0aa1bab
Compare
3690251 to
4f6f274
Compare
4f6f274 to
ee93c67
Compare
joshpensky
left a comment
There was a problem hiding this comment.
thanks for taking this! left a few comments about splitting this out
Why
Fixes a bug where CVC validation fails automatically when card number validation fails
Since CVC validation is based on card number, we should wait until the card number is valid first
Before
Screen.Recording.2026-02-02.at.16.41.14.mov
After
Screen.Recording.2026-02-02.at.16.40.37.mov
How
cardValidation.isValidis false