validate comma separated list using regex

前端 未结 4 978
囚心锁ツ
囚心锁ツ 2021-01-17 01:23

I want to validate that the user has entered a comma separated list of words only using regex, will this work/is there a better way:

 $match = \"#^([^0-9 A-z         


        
4条回答
  •  旧时难觅i
    2021-01-17 01:47

    I suggest, if you want to test regular expressions, to use kiki.

    About your regex: it won't work because of unmatched parentheses. Some more things to take into account:

    • You currently disallow numbers, a space and letters A-z. I think [0-9a-zA-Z ] was what you had in mind, although that still filters out letters like ö.
    • You are currently forcing a space after each comma
    • The dollar sign as an end anchor won't work unless it's the last character of the regex (excluding the #)

    Besides, what's the point of validating whether or not this is a comma-seperated list?

提交回复
热议问题