Timeline for How can I validate an email address in JavaScript?
Current License: CC BY-SA 4.0
62 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 31, 2023 at 18:18 | history | edited | Ben | CC BY-SA 4.0 |
wording
|
Aug 27, 2023 at 15:19 | comment | added | wpmarts | function validateEmail(email) { // Regular expression pattern for email validation const pattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; return pattern.test(email); } // Test the function const email = "[email protected]"; if (validateEmail(email)) { console.log("Email is valid."); } else { console.log("Email is not valid."); } | |
Aug 22, 2023 at 18:41 | comment | added | Lucian | @GautamParmar, actually [email protected] is valid. If you have a gmail account, test it (add a + before @ in yours). | |
Mar 24, 2023 at 12:03 | history | edited | Graham John | CC BY-SA 4.0 |
Improved the legibility of the answer: rephrased it for brevity, and corrected the grammar.
|
Jul 17, 2022 at 8:55 | history | edited | Idrizi.A | CC BY-SA 4.0 |
add snippet
|
Apr 29, 2022 at 12:47 | comment | added | Gabriel Chaves Becchi | Invalidates valid emails, such as [email protected] | |
Mar 17, 2022 at 20:20 | history | edited | Mario Varchmin | CC BY-SA 4.0 |
Fixed a typo
|
Jan 26, 2022 at 14:05 | history | edited | Nero Vanbiervliet | CC BY-SA 4.0 |
First line of code block had invalid JS syntax (forgot to open function body)
|
Nov 25, 2021 at 12:53 | history | edited | theProCoder | CC BY-SA 4.0 |
improved formatting
|
Nov 5, 2021 at 9:01 | comment | added | Code Cooker |
this is invalid sean.o'[email protected] and your code couldn't verify that, It says valid email.
|
|
Oct 17, 2021 at 23:29 | comment | added | PlexQ | @lasmini Gomes this regex is hopelessly naive. brian@li is a valid email address. also [email protected] is also valid. Also [email protected] is also valid. And is use A LOT by testers because the +123 is ignored by gmail. | |
Sep 24, 2021 at 12:26 | comment | added | Iasmini Gomes | This kind of email [email protected] is not validated by the regex from the answer. I've tested this one and it worked: ^[\w.]+@[a-z]+.\w{2,3}$ | |
Aug 16, 2021 at 6:35 | comment | added | Abhi Beckert | @KevinFegan You can't validate an email address, but you can recognise obviously invalid ones. Basically anything that will stop your outgoing mail server from even attempting to send the message. | |
Aug 6, 2021 at 6:33 | comment | added | Gautam Parmar | [email protected] - showing is valid which should not | |
Jul 16, 2021 at 23:02 | comment | added | undefined |
@KevinFegan let's be realistic: you would not be using JavaScript to confirm whether an e-mail is authentic. I see this validation as perfectly reasonable when a user signs up. You probably do not want to bother sending verification e-mails to addresses that cannot possibly exist. Some might also have outbound e-mail limits, making it north worth it to send e-mails to email@localhost , i don't have an email or any other funny user inputs.
|
|
Jul 16, 2021 at 22:56 | history | edited | undefined | CC BY-SA 4.0 |
form submission redirects the snippet away, use `input` event for simpler "live" results
|
Dec 13, 2020 at 17:37 | history | edited | Robert Hovhannisyan | CC BY-SA 4.0 |
There was a 2 useless escapes according to ESlint
|
May 24, 2020 at 18:07 | history | edited | Mathyou | CC BY-SA 4.0 |
Changed all 'var' to 'const', the modern convention for Javascript.
|
Mar 21, 2019 at 11:46 | history | edited | frzsombor | CC BY-SA 4.0 |
".bind()" is deprecated as of jQuery 3.0, use ".on()" instead
|
Jan 18, 2019 at 1:20 | history | edited | Elias Zamaria | CC BY-SA 4.0 |
Fixed Chromium link
|
Dec 18, 2018 at 14:04 | history | edited | Prakash Pazhanisamy | CC BY-SA 4.0 |
removed space
|
Oct 8, 2018 at 12:11 | review | Suggested edits | |||
Oct 8, 2018 at 13:08 | |||||
Mar 16, 2018 at 21:33 | history | edited | gyo | CC BY-SA 3.0 |
Little jQuery improvement
|
Jan 25, 2018 at 22:53 | history | edited | Alexander Mills | CC BY-SA 3.0 |
added 8 characters in body
|
Dec 13, 2017 at 18:55 | history | edited | itsdarrylnorris | CC BY-SA 3.0 |
Adding support non cases sensitive emails by lower casing the email before running the test.
|
Oct 10, 2017 at 12:33 | history | edited | alexkasko | CC BY-SA 3.0 |
fixed, what I beleive is a typo in first regex, escaping closing bracket after @
|
Oct 9, 2017 at 4:23 | review | Suggested edits | |||
Oct 9, 2017 at 5:10 | |||||
Dec 23, 2016 at 0:36 | review | Suggested edits | |||
Dec 23, 2016 at 1:13 | |||||
Dec 13, 2016 at 10:36 | history | edited | albciff | CC BY-SA 3.0 |
change submit event to click event because the generated iframe to run the code snippet is blocked due to: "is sandboxed and the 'allow-forms' permission is not set."
|
Sep 16, 2016 at 13:38 | review | Suggested edits | |||
Sep 16, 2016 at 15:57 | |||||
Jun 20, 2016 at 15:26 | review | Suggested edits | |||
Jun 20, 2016 at 16:04 | |||||
Jun 2, 2016 at 16:58 | history | edited | Manuel Araoz | CC BY-SA 3.0 |
small fix in snippet
|
Jun 2, 2016 at 14:05 | history | edited | rnevius | CC BY-SA 3.0 |
added 1025 characters in body
|
Mar 3, 2016 at 10:53 | history | edited | Endless | CC BY-SA 3.0 |
added a bunch of existing tests
|
Feb 9, 2016 at 10:52 | history | edited | Yura | CC BY-SA 3.0 |
forgotten to escape here to
|
Feb 9, 2016 at 10:37 | history | edited | Yura | CC BY-SA 3.0 |
I don't know why it works in js but in java in won't compile cause illegal to have "[[" construction and you need to escape like "[\["
|
Dec 7, 2015 at 10:48 | history | edited | Piskvor left the building | CC BY-SA 3.0 |
reverted Rev7, as it introduces completely unrelated behavior ("TLDs are never >8 characters")
|
Dec 7, 2015 at 10:47 | history | rollback | Piskvor left the building |
Rollback to Revision 7
|
|
Jul 9, 2015 at 17:27 | history | edited | Kee | CC BY-SA 3.0 |
Add updated example regexp from demo that works for unicode email addresses.
|
Mar 30, 2015 at 7:02 | review | Suggested edits | |||
Mar 30, 2015 at 7:24 | |||||
Mar 30, 2015 at 6:32 | review | Suggested edits | |||
Mar 30, 2015 at 6:55 | |||||
Mar 30, 2015 at 5:52 | review | Suggested edits | |||
Mar 30, 2015 at 6:21 | |||||
S Mar 27, 2015 at 7:54 | history | suggested | CommunityBot | CC BY-SA 3.0 |
We dont have use any special characters for this email address.
|
Mar 27, 2015 at 7:25 | review | Suggested edits | |||
S Mar 27, 2015 at 7:54 | |||||
Mar 9, 2015 at 0:34 | history | edited | SeanCannon | CC BY-SA 3.0 |
removed redundant character escapes
|
Apr 8, 2014 at 12:24 | review | Suggested edits | |||
Apr 8, 2014 at 12:25 | |||||
Apr 8, 2014 at 12:20 | review | Suggested edits | |||
Apr 8, 2014 at 12:21 | |||||
Apr 8, 2014 at 12:16 | review | Suggested edits | |||
Apr 8, 2014 at 12:18 | |||||
Feb 1, 2014 at 8:49 | comment | added | Kevin Fegan |
You cannot validate email addresses, period. The only one who can validate an email address is the provider of the email address. For example, this answer says these email addresses: %[email protected], "%2"@gmail.com, "a..b"@gmail.com, "a_b"@gmail.com, [email protected], [email protected] , [email protected] are all valid, but Gmail will never allow any of these email addresses. You should do this by accepting the email address and sending an email message to that email address, with a code/link the user must visit to confirm validity.
|
|
Jan 23, 2014 at 17:01 | history | edited | Eduardo Ponce de Leon | CC BY-SA 3.0 |
When copying pasting the function spaces on the regular expression give errors, I put it all together
|
Jan 16, 2014 at 23:58 | review | Suggested edits | |||
Jan 17, 2014 at 0:00 | |||||
Sep 11, 2013 at 2:21 | history | made wiki | Post Made Community Wiki by pera | ||
Aug 24, 2013 at 20:41 | history | edited | Peter Mortensen | CC BY-SA 3.0 |
Copy edited.
|
Mar 29, 2013 at 17:39 | review | Suggested edits | |||
Mar 29, 2013 at 17:42 | |||||
Nov 1, 2012 at 7:27 | review | Suggested edits | |||
Nov 1, 2012 at 7:36 | |||||
Oct 26, 2012 at 6:32 | comment | added | Vroo | This doesn't even accept the examples in RFC 822. Some simple cases it doesn't match a\@[email protected], a(b)@c.com. See the RFC for more. Here's a regex that won't reject any valid addresses [^@]+@[^@]+\.[^@]+ and protects against common errors. | |
Jan 17, 2012 at 7:04 | review | Suggested edits | |||
Jan 17, 2012 at 7:52 | |||||
Jan 12, 2012 at 12:27 | history | edited | ripper234 | CC BY-SA 3.0 |
Add a live demo
|
Sep 25, 2011 at 9:18 | history | edited | Yi Jiang | CC BY-SA 3.0 |
deleted 1 characters in body
|
Sep 8, 2010 at 2:34 | comment | added | Randal Schwartz | This regex eliminates valid, in-use emails. Do not use. Google for "RFC822" or "RFC2822" to get a proper regex. | |
Sep 5, 2008 at 17:47 | vote | accept | pix0r | ||
Sep 5, 2008 at 16:15 | history | answered | John Rutherford | CC BY-SA 2.5 |