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
开发者_如何学JAVA1,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.
精彩评论