简体   繁体   English

数字逗号分隔的正则表达式

[英]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.我正在使用正则表达式/^[0-9]+((?:[,][0-9]{0,20})?)$/g这里我可以输入数字,数字。 but i want to add more digit.但我想添加更多数字。

I have created sample app on Stackblitz我在Stackblitz上创建了示例应用程序

For example digit, digit,...nth number.例如数字、数字、...第n个数字。

Valid inputs:有效输入:

1234567890
123,321,467,56,1

Invalid inputs:无效输入:

1123,,456
,123,456,
123,

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);在您的appPhoneNumber指令和const matches = control.value.match(/^(\\d+\\,?)*\\d+$/g); in app.componentapp.component

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM