Validation : valid_url rule |
[eluser]xwero[/eluser]
Today i noticed valid_url is still in the language file of the validation library but it isn't in the code and it isn't documented? Is this an oversight? Or are there plans to restore the rule?
[eluser]Derek Allard[/eluser]
We can add this in. The problem now is what do we consider a valid URL?
[eluser]Derek Allard[/eluser]
Yeah, that could work, but I think we'd need to suppress errors if an segment is absent or malformed. A regex might be the most flexible, but then again, the question is, what is a url, and how stringent do we want to be. I'm thinking we probably just want to be very broad here. optional protocol (http or ftp, etc), alpha-dash with a dot with 2 or more alpha after it, then anything after that. It would allow for http://www.site.com/~user ftp://site.com:80 you know... those types of things.
[eluser]Seppo[/eluser]
Well... I've tried to do some regex recently for that, but there are ALWAYS URLs that are not exactly valid that but they are actually used...Yahoo, for example, uses ; and , in their news URL titles. Our valid_url function finally is Code: return preg_match('/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:;.?+=&%@!\-\/]))?/',$url) > 0;
[eluser]Derek Allard[/eluser]
Yup! And therein lies my problem - what does CI consider "valid" or validation purposes. $specific_declared_protocol_assume_http $\w*\.\w[2-4].* ???? Its tough. |
Welcome Guest, Not a member yet? Register Sign In |