-1

I am trying to write RegExp for validation

  1. string will be alphanumeric with not having space between words.
  2. after each word comma will be added by user and after that space get added
  3. not allow space and comma in end of word and not allow more than 5 comma separated values

I wrote following regExp code but it fails on second.

^[0-9a-zA-Z]+(\, [0-9a-zA-Z]+){0,4}$
halfer
  • 18,701
  • 13
  • 79
  • 158
Saurabh Gujarani
  • 451
  • 1
  • 7
  • 21

1 Answers1

0

I think you want:

^[0-9a-zA-Z]+(?:, [0-9a-zA-Z]+){0,4}$

https://regex101.com/r/vYdOoL/1

MonkeyZeus
  • 18,445
  • 3
  • 30
  • 67