0

I need to validate the email input by the user. It has to have an "@" somewhere in the address with a "." somewhere after the @. If it's not in the correct format, I need to store the address as "invalid@address.given". Any help would be appreciated!

2 Answers2

2

This is an incredibly difficult thing to do properly. See the following link for a discussion of just how hard: https://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/

The correct thing to do is to try and send an email to the supplied address and include a call back URL to validate account.

hardillb
  • 54,545
  • 11
  • 67
  • 105
0

see that: How to validate an email address using a regular expression?

the regex:

(?:[a-z0-9!#$%&'+/=?^_{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_{|}~-]+)|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])")@(?:(?:a-z0-9?.)+a-z0-9?|[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])).){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-][a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])