django validate email field code example
Example 1: email validation using django
from django import forms
class MyForm(forms.Form):
even_field = forms.IntegerField(validators=[validate_even])
Example 2: email validation using django
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
def validate_even(value):
if value % 2 != 0:
raise ValidationError(
_('%(value)s is not an even number'),
params={'value': value},
)