-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 xxx.yyy@gmail.com. But I need to check addresses like xxx.yyy@yahoo.co.in. 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("xxx.yyy@yahoo.co.in")
except:
    # not valid email
yamm
  • 1,523
  • 1
  • 15
  • 25
  • no it's not working when i pass the value "xxx.yyy@yahoo.coin" it's a wrong value which i passed – Python Team May 12 '15 at 12:13
  • mhh what version of django are you using? i tested this with 1.4 and 1.8 and it works for me – yamm May 12 '15 at 12:16
  • ok, wait is `xxx.yyy@yahoo.co.in` valid for you or not?? because for django this would be a valid email address. – yamm May 12 '15 at 12:36