If you want to check all anchor tags, you can do this. Checking RegEx checks for typos AKA fat fingers.
function checkRelpath(){ var anChrs = $('a'); $.each(anChrs, function(idx, itm){ var pattern = new RegExp('/^(http|https|http:|https:|\/\/)/'), path = $(itm).prop('href'), testPath = pattern.test(path); console.log(path); console.log(testPath); }); }
Or, if you want to test a specific anchor, you can do it.
function checkThisRelpath(a){ var pattern = new RegExp('/^(http|https|http:|https:|\/\/)/'), path = $(a).prop('href'), testPath = pattern.test(path); console.log(path); console.log(testPath); }
source share