Use WHATWG URL for url and email validation
See original GitHub issueVia 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;
}
};
Issue Analytics
- State:
- Created 6 years ago
- Comments:10
Top Results From Across the Web
How to configure URL validation in your app - TinyMCE
Necessary steps for setting URL validation within your app. Use our Link checker plugin to validate links without opening or clicking on ...
Read more ><input type="url"> - HTML: HyperText Markup Language | MDN
The input value is automatically validated to ensure that it's either empty or a properly-formatted URL before the form can be submitted.
Read more >4.10.5 The input element - HTML Standard - whatwg
Constraint validation: While the value of the element is neither the empty string nor a valid absolute URL, the element is suffering from...
Read more >Which characters make a URL invalid? - Stack Overflow
When validating, you should always "think positive": ask for "what is valid", everything else is invalid. Testing against the (few) valid ...
Read more >validator - crates.io: Rust Package Registry
Common validation functions (email, url, length, . ... This implementation uses finite automata and guarantees linear time matching on all inputs.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
mailto:a@b
is a valid URL as well, but I would think thata@:*&^:
is not a valid email address. However: https://github.com/jsdom/whatwg-url/issues/98universal-url
is, to my knowledge, 100% TR46 compliant.universal-url-lite
has two shims, one with incomplete TR46 and one that relies on the native browser implementation, which all are currently incomplete.That’s all I can think of at the moment.