用于 url 验证的 Javascript 和 PHP 正则表达式
所以我看到了许多类似的问题和答案,但找不到适合我的特定需求的解决方案。
我对正则表达式很糟糕,并且正在努力为以下 url 验证获得一个简单的正则表达式。
domain.com
domain.com/folder
subdomain.domain.com
subdomain.domain.com/folder
还可以验证可选的 http:// 和 http://www。会非常有帮助的。谢谢!
Possible Duplicate:
Regular expression for URL validation (in JavaScript)
So I've seen many similar questions and answers but can't find a solution that fits my specific needs.
I'm terrible at Regex's and am struggling to get a simple Regex for the following url validation.
domain.com
domain.com/folder
subdomain.domain.com
subdomain.domain.com/folder
also to validate for optional http:// and http://www. would be super helpful. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,
请注意,您的问题并未将 URL 限制为一组协议、TLD 或字符集。
skype://18005551212
或gopher://localhost
之类的内容是有效的 URL。哎呀,根据您使用的浏览方式,以下可能都是访问同一服务器的有效方法(尽管虚拟主机不完全相同):它们都在 Firefox 中为我工作。
如果您需要进一步的限制,请确定它们是什么。你愿意牺牲有效的协议吗?您真的只对一两个协议感兴趣吗?
更具体的问题将为您带来更具体的答案。
As near as I can get would be:
Note that your question hasn't limited URLs to a set of protocols, TLDs or character sets.
Something like
skype://18005551212
orgopher://localhost
is a valid URL. Heck, depending on what you're using to browse, the following might all be valid ways to get to the same server (though not quite the same virtualhost):They all work for me in Firefox.
If you want further restrictions, determine WHAT they are. Are you willing to sacrifice valid protocols? Are you really only interested in one or two protocols?
A more specific question will get you a more specific answer.