Jump to content

validating the url in a form field


jimfog

Recommended Posts

I just noticed-by running tests- that in order for a web address to pass the php validation url filter it MUST be accompanied by the "http" in the beginning of the url. That said www.xxxx..com will not PASS the filter. From my point of view I think I must write extra checks because the user might write the web address without the "http". What do you do in a similar situation like this?

Link to comment
Share on other sites

i would try replacing the "www." with "http://www."....

function add_http($text){// set http: on www.  $text = preg_replace( '"www\."', "http://www.", $text );// remove duplicates after set   $text = preg_replace( '"http://http://www\."', "http://www.", $text );   $text = preg_replace( '"https://http://www\."', "https://www.", $text );}

Edited by Rollins
Link to comment
Share on other sites

...and what I would do if the URL submitted by the user has already the http in it? I think I must write a conditional in this case.

Link to comment
Share on other sites

filter_validate_url should catch a http://random.com type url from what i have found.... the example you posted has a double dot...if u use that to test it could screw up the results aswell. i think.... :) "That said www.xxxx..com will not PASS the filter."

Link to comment
Share on other sites

filter_validate_url should catch a http://random.com type url from what i have found.... the example you posted has a double dot...if u use that to test it could screw up the results aswell. i think.... :) "That said www.xxxx..com will not PASS the filter."
Forget the example with the double dot. A mistyped.
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...