Regex to match comma separated values?

六眼飞鱼酱① 提交于 2021-02-11 15:41:12

问题


I am looking for a regular expression which accepts comma separated values(no space) of both string and numbers(especially mobile numbers, 10 digits) for client side validation.

I have gone through regexlib.com but i couldn't find good one.

UPDATE

Input patterns:

9655770780,college,8095145098,schoolmates

Its a just a input field, users can enter group name of mobile numbers or just the numbers.

Any suggestions!


回答1:


Regular expressions may be overkill for this problem.

You could use:

var csv_values = csv_string.split(",");

This would split on the commas and give you your values




回答2:


Try this pattern. This will verify if a text is a comma separated

([a-zA-Z0-9]+,)+


来源:https://stackoverflow.com/questions/4733319/regex-to-match-comma-separated-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!