Validating url with jQuery without the validate-plugin?

后端 未结 7 694
情书的邮戳
情书的邮戳 2020-11-28 23:06

I need to validate a url in variable with jQuery, but can\'t use validate-plugin. Is there a simple way to do this?

7条回答
  •  心在旅途
    2020-11-28 23:43

    Thank you very much Meo and Nick, I put both your answers together and it works just great.

    if(/^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i.test($("#url").val())){
        alert("valid URL");
    } else {
        alert("invalid URL");
    }
    

提交回复
热议问题