[英]Using javascript/jquery, validate URL that should have http or https and www
Please advice how to validate a url that should have http or https and www in it请建议如何验证应该有 http 或 https 和 www 的 url
Thanks Amit谢谢阿米特
Try this one:试试这个:
^(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?
var re = /^(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
alert(re.test(yourString));
you could use:你可以使用:
function checkhttpWww(s) {
var reg = /http(s?):\/\/www/;
return reg.test(s);
}
function is_correct(x) {
return /^http[s]?:\/\/www\./.test(x);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.