mrmBot-Matrix/utils/urlcheck.js

17 lines
394 B
JavaScript
Raw Normal View History

2019-09-13 20:02:41 +00:00
module.exports = (string) => {
var protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/;
var domainRE = /^[^\s.]+\.\S{2,}$/;
var match = string.match(protocolAndDomainRE);
if (!match) {
return false;
}
var everythingAfterProtocol = match[1];
if (!everythingAfterProtocol) {
return false;
}
if (domainRE.test(everythingAfterProtocol)) {
return true;
}
return false;
};