Earlier quoted context omitted.
The regex listed there isn’t that much more complex. It’s basically a check for *@a*.* where * is some minimal whitelist of valid characters and a is an alphanumeric to start the domain name.
And even though that sounds reasonable, it is still wrong. Technically, you do not even need the dot, if you add an MX record to a whole TLD or have some other funky DNS setup. Source: https://www.netmeister.org/blog/email.html
Ruby's Email Address Regexp
31–40 of 69 posts
Re: Ruby's Email Address Regexp
#32There are basically three levels of address checking: 1) You need to validate an email field for login or a website - checking for an @ mark with some text before and at least one . after the @ will do for this. 2) You need to do some sort of address validation, library regexps like this will do for 99.9...% of these. 3) You are building an email handling system which needs to actually support the RFCs, in which case…
Re: Ruby's Email Address Regexp
#33Earlier quoted context omitted.
The regex listed there isn’t that much more complex. It’s basically a check for *@a*.* where * is some minimal whitelist of valid characters and a is an alphanumeric to start the domain name.
And even though that sounds reasonable, it is still wrong. Technically, you do not even need the dot, if you add an MX record to a whole TLD or have some other funky DNS setup. Source: https://www.netmeister.org/blog/email.html
> This requirement is a willful violation of RFC 5322, which defines a syntax for email addresses that is simultaneously too strict (before the "@" character), too vague (after the "@" character), and too lax (allowing comments, whitespace characters, and quoted strings in manners unfamiliar to most users) to be of practical use here.
Personally, I say if it's good enough for Web browsers, it's probably good enough for your app.
Re: Ruby's Email Address Regexp
#34There are basically three levels of address checking: 1) You need to validate an email field for login or a website - checking for an @ mark with some text before and at least one . after the @ will do for this. 2) You need to do some sort of address validation, library regexps like this will do for 99.9...% of these. 3) You are building an email handling system which needs to actually support the RFCs, in which case…
technically not required...
[adam@solomon]$ dig +noall +answer mx ai
ai. 21572 IN MX 10 mail.offshore.ai.Re: Ruby's Email Address Regexp
#35Earlier quoted context omitted.
Never mind the regex, `email.indexOf("@") > 2` does the trick and faster if you happen to need to check many emails. All websites these days require verification of emails (regardless of whether or not it's necessary), and if that's not enough validation, I don't know what is!
I would use `email.includes('@')`, it only needs to be polyfilled for IE since it's in every modern browser JS engine.
Re: Ruby's Email Address Regexp
#36The best email regex just checks for an @ symbol with something before it, and something after it. Anything more complex is a waste of time.
Never mind the regex, `email.indexOf("@") > 2` does the trick and faster if you happen to need to check many emails. All websites these days require verification of emails (regardless of whether or not it's necessary), and if that's not enough validation, I don't know what is!
Re: Ruby's Email Address Regexp
#37Earlier quoted context omitted.
This depends on your use-case. If you're writing a mail agent, then you do probably want to parse email addresses in their entirety. If you're writing a website that accepts email addresses and wants to make sure the user doesn't just type "foo", then yeah, check for `.+@.+` and call it a day.
If you are writing a webpage that accepts email addresses, then please just use and check for: document.querySelector("[type='email']").validity.valid This will not only give you email validation for free, but also gives users with software keyboards (e.g. on phones) a contextual keyboard.
Re: Ruby's Email Address Regexp
#38Earlier quoted context omitted.
Never mind the regex, `email.indexOf("@") > 2` does the trick and faster if you happen to need to check many emails. All websites these days require verification of emails (regardless of whether or not it's necessary), and if that's not enough validation, I don't know what is!
Why 2? Greater than 0, sure.
Re: Ruby's Email Address Regexp
#39There are basically three levels of address checking: 1) You need to validate an email field for login or a website - checking for an @ mark with some text before and at least one . after the @ will do for this. 2) You need to do some sort of address validation, library regexps like this will do for 99.9...% of these. 3) You are building an email handling system which needs to actually support the RFCs, in which case…
You need an address backed by an actually valid mailbox. At which point you need to send an email to the address to validate.
Re: Ruby's Email Address Regexp
#40SMTP had a very useful VRFY command after you've tested for the @ and MX record, but only a handful of service providers will tell you if the email is invalid nowadays due to spam concerns. Gmail still does though, which is a big deal as 90% of people who register on my sites are using a gmail address only and thus easy to verify instantly and notify the user to double check the email spelling.