Jump to content

Regex : better solution than ^[0-9]+(,[0-9]+)*$ ?

Recommended Posts

Hi All,


I have a preg_match that checks if a string is made up of a number, or of a comma-separated list of numbers. The regex is :


When the form is processed, the browser crashes if the string is very long. (It does not if I just do not run the preg_match).


I guess the solution might be adjusting the pcre.backtrack_limit setting. However I would like to know if there is a better solution than the above preg_match to check the string.



Share this post

Link to post
Share on other sites

Just a random thought.. I don't know full context so this may or may not be something you can do, but I assume if it's a list of numbers you will split at the comma and loop anyways.. why not just simplify to


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.