简体   繁体   中英

Regex for input text box

I have a text box for user input where user can enter only comma separated numbers. Comma at the end of the string is also allowed

I am done with regex for that

var regex=/^[0-9\,]+$/;

How to apply higher bound limit on each comma separated number?

lets say, maximum number is 10 digit

following is valid

11,22,333,555555 and

11,23,

following is invalid

111111111111111111111111,4,4

jsfiddle here

Use the following pattern:

var regex = /^[0-9]{1,10}(?:,[0-9]{1,10})*$/;

This says to match any number of 1 to 10 digits, followed by a comma and another 1-10 digit number, this quantity zero or more times.

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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