How to use EmailField ?

EmailField is used for storing an email address in the database. One can store email id form any domain. Let’s try storing an email id instance in model created above. 

Python3




# importing the model
# from geeks app
from geeks.models import GeeksModel
 
# creating a string
d = "abc@gmail.com"
 
# creating an instance of
# GeeksModel
geek_object = GeeksModel.objects.create(geeks_field = d)
geek_object.save()


Now let’s check it in admin server. We have created an instance of GeeksModel.

EmailField – Django Models

EmailField is a CharField that checks the value for a valid email address using EmailValidator. EmailValidator validates a email through predefined regex which checks ‘@’ and a ‘.’ defined after it. One can change the regex by exploring options from EmailValidator itself. Syntax

field_name = models.EmailField(max_length=254, **options)

EmailField has one extra required argument:

EmailField.max_length

The maximum length (in characters) of the field. The max_length is enforced at the database level and in Django’s validation using MaxLengthValidator.

Similar Reads

Django Model EmailField Explanation

Illustration of EmailField using an Example. Consider a project named geeksforgeeks having an app named geeks....

How to use EmailField ?

...

Field Options

...

Contact Us