How to detect whether a string is in URL format using javascript?

前端 未结 7 1845
轻奢々
轻奢々 2020-12-18 19:52

I think the question title seems to explain eveything. I want to detect whether a string is in URL format or not using javascript.

Any help appreciated.

7条回答
  •  Happy的楠姐
    2020-12-18 20:51

    try something like this:

    function isUrl(s) {
        var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)? (\/|\/([\w#!:.?+=&%@!\-\/]))?/
        return regexp.test(s);
    }
    

提交回复
热议问题