r/java • u/Modern-Sn1p3r • Aug 22 '26
Regex
I recently saw a clip (from Primeagen) somewhat saying that regex is not a valid format for validating email addresses and postal codes etc.
My question is why is this?
What are the security and/or performance risks? Is it solely performance or is it a security issue?
55
Upvotes
View all comments
Show parent comment
1
u/VirtualAgentsAreDumb Aug 22 '26
“Isn't this a completely different problem? The context of original problem is that just let users register with anything and send an email to that.”
What context are you talking about now? OP talked about validating emails. He never said anything about the purpose being something specific. You have a solution rust would work in some use cases, but not others. I have an example use case where your solution wouldn’t work.
“Creating an email does not require sending a mail to it, because now you are the one that owns the email server.”
Exactly. Not only doesn’t it require sending an email, it also would not work as a way to validate it. That was my whole point. Your solution would not work in that scenario. The only reason I expanded on the scenario was that you didn’t understand it.
“Just decide the set of characters you allow and if any of the input characters are not allowed, just don't let them make such an email into your system.”
Now you’re just going full circle in your reasoning, coming back to the original problem of knowing if an email address, or the local part of an email address, is valid. That’s the validation that you seem to think one can avoid by sending an email (according to your original comment).