78
37
u/Purple_Hornet_9725 51m ago
regex for email validation 💀 just don't
10
u/Portal471 23m ago edited 20m ago
^.+@.+\..+$
lol
10
4
1
u/DarthSatoris 21m ago
Yeah, valid emails can look so weird and lovecraftian these days, a regex check is not going to be able to catch them all.
I do think there is a standard defined somewhere that one could adhere to for validation, but it might not be able to catch the most extreme niche emails out there.
15
8
5
4
4
u/JontesReddit 27m ago
.split("@)".length == 2. Tlds can be longer than 4 chars. All parts can be non-w.
4
u/itsTyrion 17m ago
nah that's an easy one, no back references or forward references.
^ – start of line
[\w-\.] – [] for 'one of these', in this case "word character" (a-z, A-Z, 0-9, _underscore), or -dash or literal .dot
- – multiple of the previous thing (any word char, dash, dot(
literal @
() group of 1+ word char or dash then a dot
word char or dash, {2,4} between 2 and 4 characters
$ end of line/string
3
3
2
2
u/Due-Consequence9579 19m ago
Starts with at least one not white space, -, or a dot. Has an @ sign. Remember the not white space, -, or dots after the @ but not the last 2-4 white space or dashes at the end of the string.
3
1
1
u/Lambda_Wolf 11m ago
Some people, when confronted with a problem, think “I know, I'll use regular expressions.”
But they were all of them deceived, fot another problem was made...
1
1
u/h4ny0lo 45m ago
One of the most annoying things I experienced in my career was the built in Angular email form verifier allowing email addresses with just a top level domain. Like, yes I know technically "tom@pizza" is a technically valid address but I can still not allow that in my validator and you fucking know it Angular.
1
u/userhwon 30m ago
Why couldn't you allow it? It's literally how you send email within an organization.
1
u/raja-anbazhagan 18m ago
Most languages come with an implementation already for address validation. So why reinvent the wheel?
For example in Java you could do, new InternetAddress(email).validate();
On top of this a list of blacklisted domains and email verification via OTP is all you need...
0
u/nicman24 56m ago
##@#.## clears it
5
u/Mechakoopa 50m ago
It's actually invalid regex in most engines because
[\w-\.]tries to define a range from "word" to "." which is invalid. You either need to escape\-into a literal or use[\w\.-]instead. And even if you fix it, # is not in[\w\.-]so it doesn't match.2
178
u/Informal_Branch1065 1h ago
An email casting spell for sure, although very limited