+
+ def clean_email(self):
+ max_length = User._meta.get_field('username').max_length
+ email = self.cleaned_data['email']
+ if User.objects.filter(username=email).exists():
+ raise forms.ValidationError(_('User with this email address already exists.'))
+ if len(email) > max_length:
+ raise forms.ValidationError(_('Username too long. Max length: %s') % max_length)
+ return email