Stop Validating Email Addresses With Your Complex Regex
21–30 of 211 posts
Re: Stop Validating Email Addresses With Your Complex Regex
#22Re: Stop Validating Email Addresses With Your Complex Regex
#23Re: Stop Validating Email Addresses With Your Complex Regex
#24My goto for email validation is /^.+?@.+?\..+?$/ Incase I've typed it wrong, that should basically work for anything that contains at least one @ and one dot, in that order, as well as at least one character at beginning, middle and end. It's served me well thusfar. Edit for clarification: The reason I prefer this over just checking for an @ is that if you're just checking for @ a common mistake like "me@hotmail,com"…
I think that the domain part of email addresses could be an IP address. Depending on how IPv6 addresses are displayed there, they won’t contain a dot. Somewhat artificial, yes.
Re: Stop Validating Email Addresses With Your Complex Regex
#25My goto for email validation is /^.+?@.+?\..+?$/ Incase I've typed it wrong, that should basically work for anything that contains at least one @ and one dot, in that order, as well as at least one character at beginning, middle and end. It's served me well thusfar. Edit for clarification: The reason I prefer this over just checking for an @ is that if you're just checking for @ a common mistake like "me@hotmail,com"…
I thought new TLD being worked on didn't need to have dots in them. Why not just check for x@x?
^(.+)@(.+)$
max length is 254 according to the RFC I believe, so you can check for that too.
Re: Stop Validating Email Addresses With Your Complex Regex
#26Regex from the source: https://github.com/php/php-src/blob/master/ext/filter/logica...
Re: Stop Validating Email Addresses With Your Complex Regex
#27"Feeling ambitious? Then check for the dot too: /.+@.+\..+/i. Anything more is overkill." I personally prefer: /[^@]+@[^@]+\.[^@]+/ Basically the same except that it will throw an error if someone enters an extra at sign.
/^[^@]+@[^@]+\.[^@.]+$/
Re: Stop Validating Email Addresses With Your Complex Regex
#28
Of course, if your user is not using an HTML5 compliant browser, then this will be ignored.Re: Stop Validating Email Addresses With Your Complex Regex
#29Re: Stop Validating Email Addresses With Your Complex Regex
#30This has been an issue since the day I started programming for the web, back somewhere in '95. It has regularly come up on HN, and pretty much any programming related forum I've used since the mid-90's. As an industry at the heart of the information society you have to wonder what the hell we are doing wrong if we cannot stop this constant regression into well known bad practices.
What I don't understand with this ever-repeating discussion is why the complexity has to be visible. e.g.
>
> Yeesh. Is something that complex really necessary?
Many functions are complex - we put those in libraries, pushing them under the hood, and move on.What is so special about parsing email addresses that makes everyone invent their own solution - regex or otherwise?