RegEx for CSV validation + jQuery

后端 未结 2 967
闹比i
闹比i 2021-01-17 04:52

Using jQuery validation plugin but it has no CSV validation. I have made an additional validation for this but can\'t get the RegEx right.

Here is what I have:

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-17 05:38

    Maybe I'm not totally understanding what you need, but it seems like you could capture all the values with this regex:

    /([^,]+),?/
    

    This will allow spaces and special characters in the values, I'm not sure if you want that or not, since your attempt seemed to be trying to only allow word characters.

    If you are just trying to check whether they entered something valid or not though, I'm not sure what you would want to consider "invalid". It seems to me that just about anything would be valid. If it doesn't have any commas, it's a single value. If it does, it's multiple values. Maybe if you give some more detail about what data you're expecting I can write a better validating expression.

提交回复
热议问题