Enigma
Enigma

Reputation: 859

Credit Card separated by comman - Regex - Javascript

I've textfield which is accepting credit card numbers separated by comma(,)

Current Regex I'm using is :

/(\d{16})(?:,|$)/g

This regex allows :

1. 1234567891234567,1234567891234561,1234567891234564
2. 1234567891234567,1234567891234561,123456 (as well)

I need to apply regex which is 16 Digits (No specific Card number criteria but just 16 digits) separated by comma. No trailing or leading comma. No number less or greater than 16 digits. No alphabets or symbol.

Needs Help!

Upvotes: 1

Views: 161

Answers (1)

anubhava
anubhava

Reputation: 786001

You can use this regex:

/^\d{16}(?:,\d{16})*$/

RegEx Demo

Upvotes: 1

Related Questions