开发者

Validating field to contain only numbers separated by commas

开发者 https://www.devze.com 2023-03-25 05:59 出处:网络
I\'m making a form validation callback in code igniter. I\'m trying to validate an input that needs to be numbers separated by commas, no spaces. For example

I'm making a form validation callback in code igniter. I'm trying to validate an input that needs to be numbers separated by commas, no spaces. For example

开发者_如何学JAVA

1,2,3,4,5 221,78,4,82,991,12 10001,10010,20010 etc

Whats the best way to validate this regex? Some other PHP wizardry?


Why not a regex like this?

/^(\d+,)*\d+$/


Here's an expression that won't require any backtracking.

/^(?:\d+(?:,|$))+$/

The non-capturing groups (?:regex) also make it faster.

0

精彩评论

暂无评论...
验证码 换一张
取 消