mrmBot-Matrix/utils/urlcheck.js
2019-09-13 15:02:41 -05:00

16 lines
394 B
JavaScript

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;
};