jimfog Posted October 28, 2013 Share Posted October 28, 2013 So far I've used php filter for validating the url. I just noticed though that URLs like http://kkk pass validation...something I do not want. Do I have to resort to regular expression? And if yes...can you give me a help on that? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 28, 2013 Share Posted October 28, 2013 That's a valid URL, so if you want to validate only a subset of URLs then yeah, you'll need to write your own validation code. You should be able to find several examples of that online to get you started though. Link to comment Share on other sites More sharing options...
jimfog Posted October 29, 2013 Author Share Posted October 29, 2013 I found a regular expression to use.It is too long to show it...I do not think it matters anyway though. I have 1 question though. What is the reason for using quote inside the pattern...here is an example: da-f]{2})|[!$&'()*+ PHP manual does not list quote as being a meta-character. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 29, 2013 Share Posted October 29, 2013 Assuming there is another square bracket on the end, that character class is matching that list of characters (!, $, &, ', etc). Link to comment Share on other sites More sharing options...
jimfog Posted October 29, 2013 Author Share Posted October 29, 2013 Ok, I understood. I have never heard/seen though of an URL having a quote. Have you? And another thing. This is the pattern I found to use for the regular expression:https://raw.github.com/jzaefferer/jquery-validation/master/src/additional/url2.js After playing a while with it I found that it is very cumbersome to wotk with such code...when errors appear they are difficult to be found Maybe I should use the validate filter at all. WHat is your opinion? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 29, 2013 Share Posted October 29, 2013 According to RFC 3986, which defines URI syntax, a single quote is a reserved character for various parts of the URI including the userinfo segment and is also reserved for future IP address syntax. http://tools.ietf.org/html/rfc3986 The regular expression you showed is pretty close to the URL filter, it is supposed to validate any valid URL. Obviously the rules are not trivial, which is why it is complex. That regular expression also allows an optional TLD like the URL you showed, so if you're going to use that anyway then you might as well just use the built-in validator. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now