# Django - Built in email validator failing

**URL:** <https://forum.djangoproject.com/t/django-built-in-email-validator-failing/2196>\
**Category:** Using Django\
**Created:** [May 1, 2020, 2:30am UTC](https://forum.djangoproject.com/t/django-built-in-email-validator-failing/2196 "2020-05-01T02:30:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eqmunir](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/eqmunir/32/1073_2.png) [@eqmunir](https://forum.djangoproject.com/u/eqmunir)\
**Post date:** [May 1, 2020, 2:30am UTC](https://forum.djangoproject.com/t/django-built-in-email-validator-failing/2196/1 "2020-05-01T02:30:45Z")

</div>

In my project, on the form, I apply the built in validate\_email validator on a field.

I apply it to one of my form fields, however it throws an error when I run the server.

Here is the code:

` from django.core.validators import MinLengthValidator, MaxLengthValidator, validate_email`

```
from django import forms

class SignupForm(forms.Form):
    email = forms.EmailField(validators=[validate_email(value='Email wrong'), MinLengthValidator(3), 
    MaxLengthValidator(255)], widget=forms.EmailInput(attrs={'placeholder': 'Email Address'}))

```

The error I receive when server is run is:  
**django.core.exceptions.ValidationError: [‘Enter a valid email address.’]**

However when I remove the brackets after validate\_email, everything works ok, however I need them as I want to override the message value displayed. Does anybody know the issue? Thanks.

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [May 1, 2020, 4:27am UTC](https://forum.djangoproject.com/t/django-built-in-email-validator-failing/2196/2 "2020-05-01T04:27:20Z")

</div>

Adding brackets calls the validator function with that value. It doesn’t replace the error message.

Instead, create [`EmailValidator`](https://docs.djangoproject.com/en/3.0/ref/validators/#django.core.validators.EmailValidator) with a custom message:

```python
... vaildators=[EmailValidator(message="Email wrong')]...

```

This calls the `EmailValidator` _class_ and returns an instance, that then can be called to validate values. For example you can do this to get an error:

```python
EmailValidator(message="Email wrong')('not-an-email')

```

Hope that helps,

Adam

---

<div class="post-metadata">

**Author:** ![eqmunir](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/eqmunir/32/1073_2.png) [@eqmunir](https://forum.djangoproject.com/u/eqmunir)\
**Post date:** [May 1, 2020, 10:17pm UTC](https://forum.djangoproject.com/t/django-built-in-email-validator-failing/2196/3 "2020-05-01T22:17:57Z")

</div>

Thank you Adam. Very helpful
