Actually it solves nothing.
Enter in : httttps/wwwww/dave.com
Visit: http://httttps/wwwww/dave.com is the result.
Not a valid url.
You need to ensure whats entered is an actual url then decide if it has http / https /www and remove add those to build the url correctly.
enter in -> ftp:// username @hostname/
Hey im here to learn
I think your going about it all wrong.
Never trust user input take what they send and say yes or no then modify it to your needs. Simply adding http or not is just simply wrong. UX point of view on a site you let your user get directed to fake address thats 1 lost user.
validate the url input then return the true value or let usre who entered sorry not valid
Then spit out the url,