2021-08-19 14:19:14 +00:00
|
|
|
export default (string) => {
|
2020-08-13 13:47:41 +00:00
|
|
|
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;
|
|
|
|
}
|
2020-08-13 13:47:41 +00:00
|
|
|
const everythingAfterProtocol = match[1];
|
2019-09-13 20:02:41 +00:00
|
|
|
if (!everythingAfterProtocol) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (domainRE.test(everythingAfterProtocol)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|