0

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!

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • You should provide some sample input patterns and what sort of output do you expect. – npinti Jan 19 '11 at 08:55
  • Could you give an example, how your data look like, and what do you intend to do with the regexp verify, split, extract? – Valentin H Jan 19 '11 at 08:56
  • Are you tackling the problem of how to handle CSV file parsing (it would be so simple if fields couldn't contain commas or newlines; it's the need for quoting that makes it nasty) or can you work with @Dancrumb's nice and simple answer? – Donal Fellows Jan 19 '11 at 09:40
  • @Donal Fellows: Its a just a input field, users can enter group name of mobile numbers or just the numbers. –  Jan 19 '11 at 09:55
  • @Tamil: OK, then Dan's given the right answer. Thanks for the clarification. (CSV files are more difficult to parse than they appear, and “comma separated” in the question made me wonder if they were involved. I now know they aren't, which is a great relief!) – Donal Fellows Jan 19 '11 at 09:58
  • Appreciate your endorsement Donal! @Tamil, general parsing of CSV files is A Hard Thing To Do once you factor in strings that may also contain commas or newlines or what not. – Dancrumb Jan 19 '11 at 13:23

2 Answers2

4

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

Dancrumb
  • 26,597
  • 10
  • 74
  • 130
-1

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

([a-zA-Z0-9]+,)+
KishoreK
  • 892
  • 5
  • 14