Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex to validate comma seperated string in Javascript

I want to validate comma separated string using regex.

My sample inputs

hello,hi,hey,there,where - Valid

hello hi,hey there,hey,hi - InValid(space between word should invalid)

hello,hi,hey,there,where, - Invalid - Comma at end

,hello,hi,hey,there,where - Invalid - Comma at beginning

hello,hi,,hey,there,where - Invalid - No value between 2,3 comma

I tried using this regex [0-9a-zA-Z]+(,[0-9a-zA-Z]+)* but its now working for every cases.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

just like this: ^[0-9a-zA-Z]+(,[0-9a-zA-Z]+)*$

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading