-2

I am trying to check whether the email is valid format in django. I have used syntax re.match("[^@]+@[^@]+\.[^@]+", email) for checking email is valid format. The syntax is correct but it's only for checking addresses like [email protected]. But I need to check addresses like [email protected]. How can I do that in validation? Please help me to do that. I need to check those two things in a single regex.

Thanks in advance.

yamm
  • 1,523
  • 1
  • 15
  • 25
Python Team
  • 1,143
  • 4
  • 21
  • 50

1 Answers1

4

Django has its own email validator you can use (docs)

from django.core.validators import validate_email

try:
    validate_email("[email protected]")
except:
    # not valid email
yamm
  • 1,523
  • 1
  • 15
  • 25