javascript - Regex to ensure valid querystring -



javascript - Regex to ensure valid querystring -

i'm trying come regex look can utilize javascript .test create sure scheme accepting query strings in valid format.

the format looks i=1&s1=122&s2=238&s3=167&s4=756&s5=13 can have unlimited number of s#= arguments in it, longer or shorter example.

in english language format i=1&s[1+0]=[any number > 0]&s[1+1]=[any number > 0]&s[1+2]=[any number > 0] , on.

right regex have /^([\w-]+(=[\w-]*)?(&[\w-]+(=[\w-]*)?)*)?$/ it's based on code provided in this answer. ok job of rejecting types of invalid strings, there still lot slip through.

how can improve regex look more accurately rejects invalid data?

if understand question correctly, can tighten things with:

/^i=1(&s\d+=\d+)+$/

it allow, say, s14 come before s2, query parameters supposed unordered anyway.

javascript regex query-string

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -