Created
August 11, 2015 20:52
-
-
Save akhr/5d520ab54687532a7b69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function serverUrlValidator(input){ | |
var url = input.toLowerCase(); | |
var arr = url.split('://'); | |
var protocol = arr[0]; | |
if(protocol === 'https' || protocol === 'http'){ | |
//Do nothing | |
}else if(protocol === url){ | |
url = 'https://' + url; | |
} | |
var parser = document.createElement('a'); | |
parser.href = url; | |
var protocol = parser.protocol; | |
var host = parser.host; | |
var domain = parser.domainname; | |
var port = parser.port; | |
var pathname = parser.pathname; | |
var serverUrl = protocol + '//' + host + pathname; | |
console.log('Built protocol : '+protocol); | |
console.log('Built domain : '+domain); | |
console.log('Built host : '+host); | |
console.log('Built port : '+port); | |
console.log('Built pathname : '+pathname); | |
if(host){ | |
if(protocol === 'https:'){ | |
console.log('AWESOME - URL --> '+serverUrl); | |
}else if(protocol === 'http:'){ | |
console.log('WARNING : HTTP - URL --> '+serverUrl); | |
}else{ | |
console.log('ERROR : INVALID protocol'); | |
} | |
}else{ | |
console.log('ERROR : INVALID URL'); | |
} | |
} | |
serverUrlValidator('sample.com:9000/lkjsdhf.txt') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment