from django.forms import Form, CharField, ValidationError
from django.contrib.auth.models import User


class UserChangeForm(Form):
    username = CharField(max_length=30, label='New username')

    def clean(self):
        cleaned_data = super(UserChangeForm, self).clean()

        if User.objects.filter(username=cleaned_data['username']).count():
            raise ValidationError('Username already taken!')

        return cleaned_data


class EmailChangeForm(Form):
    email = CharField(max_length=75, label='New email')

from django.forms import Form, CharField, EmailField, ValidationError
from django.contrib.auth.models import User


class UserChangeForm(Form):
    username = CharField(max_length=30, label='New username')

    def clean(self):
        cleaned_data = super(UserChangeForm, self).clean()

        if User.objects.filter(username=cleaned_data['username']).count():
            raise ValidationError('Username already taken!')

        return cleaned_data


class EmailChangeForm(Form):
    email = EmailField(max_length=75, label='New email')

Use EmailField for email validation
Use EmailField for email validation

- from django.forms import Form, CharField, ValidationError
+ from django.forms import Form, CharField, EmailField, ValidationError
  from django.contrib.auth.models import User
  
  
  class UserChangeForm(Form):
      username = CharField(max_length=30, label='New username')
  
      def clean(self):
          cleaned_data = super(UserChangeForm, self).clean()
  
          if User.objects.filter(username=cleaned_data['username']).count():
              raise ValidationError('Username already taken!')
  
          return cleaned_data
  
  
  class EmailChangeForm(Form):
-     email = CharField(max_length=75, label='New email')
+     email = EmailField(max_length=75, label='New email')
  
Use EmailField for email validation
## Code Before:
from django.forms import Form, CharField, ValidationError
from django.contrib.auth.models import User


class UserChangeForm(Form):
    username = CharField(max_length=30, label='New username')

    def clean(self):
        cleaned_data = super(UserChangeForm, self).clean()

        if User.objects.filter(username=cleaned_data['username']).count():
            raise ValidationError('Username already taken!')

        return cleaned_data


class EmailChangeForm(Form):
    email = CharField(max_length=75, label='New email')

## Instruction:
Use EmailField for email validation
## Code After:
from django.forms import Form, CharField, EmailField, ValidationError
from django.contrib.auth.models import User


class UserChangeForm(Form):
    username = CharField(max_length=30, label='New username')

    def clean(self):
        cleaned_data = super(UserChangeForm, self).clean()

        if User.objects.filter(username=cleaned_data['username']).count():
            raise ValidationError('Username already taken!')

        return cleaned_data


class EmailChangeForm(Form):
    email = EmailField(max_length=75, label='New email')
