Skip to content

Commit

Permalink
Card number validation if not numerical or a space
Browse files Browse the repository at this point in the history
  • Loading branch information
hjvoid committed Aug 12, 2024
1 parent 6e39a67 commit e9fd7f6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/utils/charge-validation-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ function containsSuspectedCVV (input) {

// Must be bound prior to use
function cardNo (cardNo) {
if (!cardNo) return 'message' // default message
const numbersAndSpacesOnly = /^[\d ]+$/;
if (!cardNo || !numbersAndSpacesOnly.test(cardNo)) return 'message' // default message
cardNo = cardNo.replace(/\D/g, '')
const cardType = creditCardType(cardNo)
if (!cardNo || cardNo.length < 12 || cardNo.length > 19) return 'numberIncorrectLength'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ describe('card validation: card number', function () {
expect(result).to.equal(true)
})

it('should strip non numbers', function () {
it('should return invalid if cardNo contains non-numbers', function () {
const result = fields.fieldValidations.cardNo('42424242424242dsakljl42')
expect(result).to.equal(true)
expect(result).to.equal('message')
})

it('should return incorrect length', function () {
Expand Down

0 comments on commit e9fd7f6

Please sign in to comment.