How to write regex to verify a comma delimited list of values

后端 未结 4 1442
日久生厌
日久生厌 2021-01-03 02:32

I am using SobiPro, a directory system for joomla and I have a field that will have values that contain alphanumerics and hyphens only, so a sample of what might be in this

4条回答
  •  不知归路
    2021-01-03 03:20

    Try this:

    [-\w\s]+(,[-\w\s]+)*
    

    [-\w\s] means a word character, space or hyphen.

    A word character usually includes _, so you may want to replace that with A-Za-z0-9 if you want to prevent this.

    [-A-Za-z0-9\s]+(,[-A-Za-z0-9\s]+)*
    

提交回复
热议问题