I'm trying to come up with a Regex expression that I can use with Javascript .test to make sure my system is only accepting query strings in a valid format.
The format looks like this i=1&s1=122&s2=238&s3=167&s4=756&s5=13
It can have an unlimited number of s#=
arguments in it, so could be longer or shorter than this example.
In English the format is something like i=1&s[1+0]=[any number > 0]&s[1+1]=[any number > 0]&s[1+2]=[any number > 0]
and so on.
Right now the regex I have is /^([\w-]+(=[\w-]*)?(&[\w-]+(=[\w-]*)?)*)?$/
It's based on the code provided in this answer. It does an ok job of rejecting some types of invalid strings, but there are still a lot that slip through.
How can I improve this regex expression so it more accurately rejects invalid data?