简体   繁体   English

使用 javascript/jquery,验证 URL 应该有 http 或 https 和 www

[英]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 to use that function:尝试使用该 function:

(function isURL(s) {
    var regexp = /http(s?):\/\/www\.[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
     return regexp.test(s);
})("https://www.google.com")

you may play with it here你可以在这里

Try this one:试试这个:

 ^(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?



var re = /^(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;

alert(re.test(yourString));

Test it at this JsFiddle .在这个 JsFiddle 测试它

Found at RegExLib .在 RegExLib 中找到

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM