Search code examples
regexvalidation

E-mail address validation using Regular Expressions


I'm writing a simple, small app that allows me to share information. I have a question on using regx to validate email address. I'm kind learning on my own. But when it comes to real-world examples, such that strings that can be validated with regular expressions, I'm kind stuck.

Exercise: Untangle the following regular expression that validates an email address:

  [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

It looks like a jumble of characters.

Can someone please explain to me how does this work?

I try to use this online resources by by Jan Goyvaerts. Any help I will appreciate it.


Solution

  • Two Suggestions I have for you.

    1. Escaping special characters is messy. 2. Email addresses are complicated. I probably recommend you to study this post if you are really interested. Please check out this other posts: Validation in Regex and Regex Help.