How can I validate a URL in perl. I mean, the query string has a specific order and all params have specific values (int or string or operator (%2B(+) ect..)).
example : http://www.mypage/question?name=john&age=21&operation=%2B
Can I control the order (name->age->operation) and the specific values of them?
Thanks
Yes and no.
No, you can’t control the order of the parameters as they’re submitted to you. Browsers may submit them in a different order, or the user may not be using a browser to submit the query to you.
Yes, you can control the order of the parameters you submit. But, don’t rely on this.
You can use Data::Validate::URI to validate a URL.
You shouldn’t use a complicated RegEx for controlling parameter values. Either the parameter matches or it doesn’t. Either the parameter value is one of the expected options, or it isn’t. If it matches, do something. If it doesn’t match anything, don’t do anything. (Or do a 404, but that can be leveraged against you.) Using anything more complex than “this parameter value should be all numbers” is asking for trouble.