1

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!

r3mainer
  • 23,981
  • 3
  • 51
  • 88
Enigma
  • 749
  • 1
  • 13
  • 35

1 Answers1

1

You can use this regex:

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

RegEx Demo

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Only 16 digits to be matched followed by comma. Your regex demo shows 123,456,789,123,456,4 as match - which is not the case. – Enigma Jul 06 '17 at 15:18
  • 1. 1234567891234567,1234567891234561,1234567891234564 --- > Should accept 2. 1234567891234567,1234567891234561,12345678 ---> should not accept – Enigma Jul 06 '17 at 15:20