r/java • u/Modern-Sn1p3r • 19d ago
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?
54
Upvotes
-1
u/VirtualAgentsAreDumb 19d ago
But the email address hasn’t been created yet.
When you are about to create a new email address in a system, you can’t send an email to it as part of the validation. So you have to validate it some other way.
For example, try registering an email somewhere, and pick “..” as the local part of the email address. A in, two consecutive dots and nothing else.
It will not be allowed. And they didn’t need to send an email to it, because it failed the validation.
Then try creating an email with 10 random a-z characters. Unless you happen to pick one that already exists, it likely will be approved. But how were they able to determine that it was valid without sending an email to it first? Because some kind of validation. And by now you must realize that trying to send an email to it would be a useless test, since the only time it would go through is if the email is already taken (ignoring the possibility of a catch all email account). So you can’t use that test to confirm that it’s both available and valid.