Javascript URL validation regex

前端 未结 3 1060
甜味超标
甜味超标 2020-12-20 22:32

I had the following url validation regex:

/(ftp|https?)://[^ \"]+$/

This is from the ref: Regular expression for URL validation (in JavaScript)

This

3条回答
  •  伪装坚强ぢ
    2020-12-20 23:20

    Try this

    function is_valid_url(url)
    {
         return url.match(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/);
    }
    

    Call the is_valid_url(YOUR_WEBSITE_URL) function everywhere which you want to website validate.

提交回复
热议问题