javascript中URL验证的正则表达式 [英] Regular expression for URL validation in javascript
本文介绍了javascript中URL验证的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用url作为输入的表单。我想使用javascript和正则表达式验证它。
I am having form which takes url as input..I want to validate it using javascript and regular expression..
它应该接受
-
www.google.com
-
google.com
-
http://google.com
www.google.com
google.com
http://google.com
如果有可能,请建议我使用正则表达式和总代码验证网址...
i尝试在很多论坛上发布的网址...但是不能得到合适的答案..
提前谢谢
Please suggest me a regular expression and total code if possible for validation of url... i tried lotta url given on many forums..but couldn't get appropriate answer.. thanks in advance
推荐答案
试试这个,
^(http\://)?[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$
这将支持
- http://google.com
- http://www.google.com
- www.google.com
- google.com
- http://google.com
- http://www.google.com
- www.google.com
- google.com
这篇关于javascript中URL验证的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文