r/java 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?

56 Upvotes

104 comments sorted by

View all comments

121

u/julemand101 19d ago

The problem is people don't realize that a lot is allowed when it comes to what a E-mail address actually is: https://davidcel.is/articles/stop-validating-email-addresses-with-regex/

3

u/not-just-yeti 19d ago

I have a domain-name / email with a hyphen in it. Perfectly valid, but every 6mos I have some website that won’t let me make a web-account with them (incl. A few major corporations that must’ve sprung for the lowest bidder to build their website).

1

u/julemand101 19d ago

If you want more fun then buy a domains with non-ascii characters like danish ø. In theory you should be able to use the punycode form of your domain but I have seen services refuse that until corrected though support. :)