[英]Fixing/cleaning user-provided URLs via Javascript
Does anyone happen to have javascript code focused on cleaning up user-provided URLs? 是否有人碰巧将JavaScript代码集中在清理用户提供的URL上? 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:
我有一个移动应用程序,要求用户输入他们的网站URL,并且很多时候URL的格式不正确,缺少http://前缀等。(在移动设备上键入内容容易出错),我经常看到类似以下内容:
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? 我知道会有一定的假设要清理URL,但是似乎那里有一个库可以清理URL?
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.
现在它处理:.co.uk或任何多部分域类型,协议,无www,无协议等。我计划将其制作为库插件。
https://github.com/WebSudosUK/framework/blob/master/com.websudos.urlMatcher.js https://github.com/WebSudosUK/framework/blob/master/com.websudos.urlMatcher.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.