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
6
u/KefkaFollower Aug 22 '26 edited Aug 22 '26
-- edited: formating and typos (Oh, so many typos) --
I lie if I say I checked the standard definition of email address. I'm guessing it must be in some RFC. But in practical terms ...
You can't use a plus sign in your email address when you are creating it. I.E. when you are choosing a public name/id for your mailbox.
You do can add plus sign and some text between the name and the "@" when you are using the address in a new email you are about to send.
Let me clarify with an example.
Let's say the mailbox address is
homero@yellowserver.com. When Homer pass its email address to other people can do it like this:homero+home@yellowserver.comhomero+work@yellowserver.comhomero+important@yellowserver.comAll this address will route the emails to the same mailbox, the one "named"
homero@yellowserver.com. Then Homero can do a little more routing of his own in his web mail page or in its email client. He can configure rules for "to:" field of incoming mail like this:homero+home@yellowserver.com--> label the mail as importanthomero+work@yellowserver.com--> move the mail from the inbox to work folder.homero+important@yellowserver.com--> mark the mail as read and move it to the recycle bin.I had used this gmail and outlook (ex msn.live (ex. hotmail)) and some at some jobs that had their own exchange server (mail server from M$).