Pregunta

Does anyone happen to have javascript code focused on cleaning up user-provided URLs? I have a mobile app that asks users to enter their website URL, and many times the URLs are not properly formatted, lack the http:// prefix, etc. (Typing on mobile tends to be error prone) I often see stuff like:

google.com
ww.google.com
http//www.goggle.com
http://www..google.com

I know there'd be a certain amount of assuming one would have to do to clean a URL, but it just seems like there would be a library out there somewhere for URL cleaning?

¿Fue útil?

Solución

I guess this is as best of a start as you can get. It now deals with: .co.uk or whatever multi-part domain types, protocol, www-less, protocol-less etc. I plan to make it a library plugin.

https://github.com/WebSudosUK/framework/blob/master/com.websudos.urlMatcher.js

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top