Krishna Rathore
Krishna Rathore

Reputation: 9687

Regular expression for number comma separated

I am using regEx /^[0-9]+((?:[,][0-9]{0,20})?)$/g .in this I am able to enter digit,digit. but i want to add more digit.

I have created sample app on Stackblitz

For example digit, digit,...nth number.

Valid inputs:

1234567890
123,321,467,56,1

Invalid inputs:

1123,,456
,123,456,
123,

Upvotes: 1

Views: 838

Answers (1)

Karmveer Singh
Karmveer Singh

Reputation: 953

Try below regex. Demo is here .

^(\d+\,?)*\d+$

Edit: Do the following changes in your project.

commaSeperatedRegEx = /^(\d+\,?)+$/g; in your appPhoneNumber directive and const matches = control.value.match(/^(\d+\,?)*\d+$/g); in app.component

Upvotes: 4

Related Questions