I think a bigger list on what is legal and what is not is in order here.
Feb 2, 2021
4
Level 1
Regex for comma separated string in validation
Hello,
I'm making an application in which I need some validation. The user is able to enter multiple zipcodes in a text input, separated by comma.
Legal input: 0000 0000,1214
Illegal use_of_letters_and_underscores_etc 000 00 0 0000, 1214 0000, 1214, 0000,1214,
I can't quite figure it out. I have tried:
regex:/^[0-9]{4}+(,[0-9]+)$/
Any help is appreciated!
Level 61
Something like this should work:
^(,?[0-9]{4}){1,}$
Or better this:
^([0-9]{4})(,[0-9]{4}){0,}?$
Or you can shorten:
^\d{4}(,\d{4}){0,}$
Please or to participate in this conversation.