mrmBot-Matrix/utils/urlcheck.js

17 lines
400 B
JavaScript
Raw Normal View History

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