Reputation: 6665
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
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?
Upvotes: 3
Views: 800
Reputation: 27943
Here's an expression that won't require any backtracking.
/^(?:\d+(?:,|$))+$/
The non-capturing groups (?:regex)
also make it faster.
Upvotes: 2