programming-examples/js/Vre1/Check whether a given value represents a domain or not.js
2019-11-15 12:59:38 +01:00

23 lines
530 B
JavaScript

function is_domain(str)
{
regexp = /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/i;
if (regexp.test(str))
{
return true;
}
else
{
return false;
}
}
console.log(is_domain('www.example.com'));
console.log(is_domain('www.npm.co.uk'));
console.log(is_domain('http://www.example.com'));
console.log(is_domain('https://www.example.com'));
console.log(is_domain('www.example.com'));