本文介绍了验证网址而不使用www.或http://的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一个URL.我已经有一个脚本来验证不允许www.
和http://
,但是我还需要验证.co.uk
.com
等.
I'm looking to validate an URL. I have already a script that validates to not allow www.
and http://
but i need to also validate for .co.uk
.com
etc.
如果输入example.co.ukff
之类的内容,我的脚本将无法运行.
My script won't run if they enter something like example.co.ukff
.
我有一个完整的URL:
I have this for a full URL:
^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i
我只需要验证结尾.co.uk
或.com
等.
I just need to validate the end .co.uk
or .com
etc.
推荐答案
尝试一下...
/^http:\/\/|(www\.)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/
它完全可以满足您的需求.
It's working exactly what you want.
需要带或不带http://, https://,
和www
.
这篇关于验证网址而不使用www.或http://的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!