Via universal-url as it covers far more edge cases such as IDNAs and IPv6 than a simple regex will.
const isEmail = email => {
try {
const url = new URL(`mailto:${email}`);
return url.search === '';
} catch (error) {
return false;
}
};
const isURL = url => {
try {
url = new URL(url);
return url.protocol === 'http' || url.protocol === 'https' || url.protocol === 'ftp';
} catch (error) {
return false;
}
};