URL regex with or without www

var urlRegex = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;

use it in your code like:

if(!urlRegex.test(targetUrl)){
        isTargetUrlValid = false;
}else{
        isTargetUrlValid = true;
}

No comments:

Post a Comment