Avatar of egoselfaxis
egoselfaxis

asked on 

Need to update URL validation javascript function to require http:// or https:// prefix

I need to update the following URL validation javascript so that it checks to make sure that the entered url is prefixed with either http:// or https://

function isValidURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
}

Please advise.

Thanks!
- Yvan

JavaScriptHTML

Avatar of undefined
Last Comment
egoselfaxis

8/22/2022 - Mon