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

前端 未结 7 1833
轻奢々
轻奢々 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:31

    Try this code. This expression is more complete and takes into account IP address:

    function checkUrl(s) {
         var regexp = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/
         return regexp.test(s); }
    

提交回复
热议问题