Skip to content

Instantly share code, notes, and snippets.

@oiljin
Last active December 10, 2020 14:41
Show Gist options
  • Save oiljin/7436b3e1076adb9ee166 to your computer and use it in GitHub Desktop.
Save oiljin/7436b3e1076adb9ee166 to your computer and use it in GitHub Desktop.
function isUrl(url) {
var re = /^(http\:\/\/|https\:\/\/)?([a-z0-9][a-z0-9\-]*\.)+[a-z0-9][a-z0-9\-]*[a-z0-9]$/i;
return re.test(url);
}
console.log(isUrl('12domain.ru')); // true
console.log(isUrl('www.domain.com')); // true
console.log(isUrl('http://domain.com')); // true
console.log(isUrl('https://domain.com')); // true
console.log(isUrl('-12domain.ru')); // false
console.log(isUrl('www.domain.c')); // false
console.log(isUrl('http://domain.com-')); // false
console.log(isUrl('https:/domain.com')); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment