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

前端 未结 7 1793
轻奢々
轻奢々 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条回答
  • 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);
    }
    
    0 讨论(0)
提交回复
热议问题