-1

recently, I started playing with Django and created a custom form for user registration. In that form to create the field for email I use something like

email = forms.EmailField()

I observed that address such as a@a.a is considered invalid by the form. Of course this is a nonsense email address. Nonetheless, I wonder how does Django checks for validity.

I found some topics on the net discussing how to check for validity of an email address but all of them were providing some custom ways. Couldn't find something talking about the django default validator.

In their docs on the email filed they specify

Uses EmailValidator to validate that the given value is a valid email address, using a moderately complex regular expression.

However that's not very specific so I decided to ask here.

2 Answers2

0

For anyone also interested in this, I would suggest looking up the implementation (django.core.validators) as was kindly suggested by iklinac in the comments.

In it, there is not just the source but also mentions about standards that were used to derive regexes that check if domain and literal have valid format.

-1

us should check docs here https://www.geeksforgeeks.org/emailfield-django-forms/#:~:text=EmailField%20in%20Django%20Forms%20is,max_length%20and%20min_length%20are%20provided.

if u wanna check validation use clean function like this :

from django.forms.fields import EmailField

email = EmailField()

my_email = "a@a.a"


print(email.clean(my_email))

if your email is valid then this func return value else return validation error

milad_vayani
  • 398
  • 1
  • 4
  • 14