Skip to main content
20 events
when toggle format what by license comment
Sep 21, 2022 at 11:44 comment added Boldewyn It would only fail, if the field is not required. In my answer I set it to be required, hence checkValidity() catches empty inputs. This was discussed above already. And the a@b case was discussed, too, namely in the very comment above yours. I’m totally unsure, what then the point of your comment is. Sorry.
Sep 21, 2022 at 11:26 comment added vikramvi This solution does work stackoverflow.com/questions/73799704/…, checkValidity fails for empty email string as well "a@b" email format
Sep 19, 2022 at 23:20 comment added Boldewyn What @KarlStephen said. Think of a web app for an intranet application. A browser rejecting e-mail addresses like user@localhost would be worse than useless. It would actively hinder the correct fill-out of the form.
Sep 19, 2022 at 18:07 comment added Karl Stephen @PhilippMochine : because sdf@sd is a valid email address : dotless domain has some specific uses where you can practically validate who can access devices that can send emails. It's not because the ICANN strongly discourages the continuation of dotless domains that the entire world must upgrade their systems with no exceptions. Like a knive, it's not because it can hurt you will prohibit it everywhere. Again, to validate an email, send one and see what happens, don't use a regex; or use a regex and accept some custommers won't stay. The point is discouraged doesn't mean invalid.
Aug 17, 2022 at 8:19 comment added Philipp Mochine I like this solution the most, but I have just noticed that sdf@sd is validated as a correct email...
Jul 24, 2022 at 19:24 comment added Boldewyn Yes, that’s because the HTML 5 spec hard-codes the regex for e-mail address validation to the 99.9% subset of RFC 2822, that is in actual use. But agreed, if you have special requirements (e.g. intranet or legacy addresses), then this solution might not cut the mustard for you.
Jul 23, 2022 at 16:19 comment added HauPham I like this solution, but it sill has some cases where it returns false instead of true. For example: email@[123.123.123.123], "email"@example.com, much.”more\ unusual”@example.com, very.unusual.”@”[email protected], very.”(),:;<>[]”.VERY.”very@\\ "very”[email protected]
Apr 10, 2022 at 14:45 comment added oelna Also worth thinking about: It's robust against future changes, as it doesn't hard-code the actual regex. I like this aspect.
Jan 30, 2022 at 13:18 comment added Boldewyn I might repeat myself, but have you noticed the input.required = true; line?
Jan 29, 2022 at 16:49 comment added marcb HTML5 'email' type accepts an empty string incase the field is not requierd. But if user decide to enter the email, it need to be valide.
Jan 2, 2022 at 17:18 comment added Boldewyn That’s what the input.required = true; line should take care of ;-)
Dec 31, 2021 at 23:00 comment added NurShomik This is the almost perfect solution. Only little thing that should be added is a check for empty field. HTML5 'email' type accepts an empty string as a valid input.
Jul 16, 2021 at 11:04 comment added Matt This should be the accepted answer by a long shot. Let browser vendors with on staff regex gurus maintain massively complicated regexes for email addresses. Your average frontend dev building a form for collecting email does not often have time to master verbose regex. Yes you have to rely on the regex the vendor provides, but if you need something more complex, do it on the server and or send an actual email and check the response
Jul 25, 2018 at 7:07 history edited Boldewyn CC BY-SA 4.0
Keeping it with the HTML5 form validation API
Jul 25, 2018 at 3:09 history edited Kevin Fichter CC BY-SA 4.0
Add null and empty string check.
May 23, 2017 at 12:26 history edited URL Rewriter Bot
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Apr 12, 2015 at 8:51 history edited Ronny CC BY-SA 3.0
Baked feature detection and basic graceful degradation in
Jun 5, 2014 at 9:03 history edited Peter Mortensen CC BY-SA 3.0
Copy edited. Added some context.
Sep 11, 2013 at 2:21 history made wiki Post Made Community Wiki by pera
Dec 20, 2012 at 15:20 history answered Boldewyn CC BY-SA 3.0