from django import forms
from django.contrib.auth.models import User

class CreateUserForm(forms.Form):
    required_css_class = 'required'
    username = forms.RegexField(regex=r'^[\w.@+-]+$',
                                max_length=30,
                                label="Username",
                                error_messages={'invalid': "This value may contain only letters, numbers and @/./+/-/_ characters."})
    email = forms.EmailField(label="E-mail")
    password1 = forms.CharField(widget=forms.PasswordInput,
                                label="Password")
    password2 = forms.CharField(widget=forms.PasswordInput,
                                label="Password (again)")

    def clean_username(self):
        existing = User.objects.filter(username__iexact=self.cleaned_data['username'])
        if existing.exists():
            raise forms.ValidationError("A user with that username already exists.")
        else:
            return self.cleaned_data['username']

    def clean_email(self):
        #if you want unique email address. else delete this function
        if User.objects.filter(email__iexact=self.cleaned_data['email']):
            raise forms.ValidationError("This email address is already in use. Please supply a different email address.")
        return self.cleaned_data['email']

    def clean(self):
        if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
            if self.cleaned_data['password1'] != self.cleaned_data['password2']:
                raise forms.ValidationError("The two password fields didn't match.")
        return self.cleaned_data
6d27c8250e88fd0c6422163a379c4104cc1b1204
<mask token>


class CreateUserForm(forms.Form):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    def clean_email(self):
        if User.objects.filter(email__iexact=self.cleaned_data['email']):
            raise forms.ValidationError(
                'This email address is already in use. Please supply a different email address.'
                )
        return self.cleaned_data['email']

    def clean(self):
        if ('password1' in self.cleaned_data and 'password2' in self.
            cleaned_data):
            if self.cleaned_data['password1'] != self.cleaned_data['password2'
                ]:
                raise forms.ValidationError(
                    "The two password fields didn't match.")
        return self.cleaned_data

<mask token>


class CreateUserForm(forms.Form):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    def clean_username(self):
        existing = User.objects.filter(username__iexact=self.cleaned_data[
            'username'])
        if existing.exists():
            raise forms.ValidationError(
                'A user with that username already exists.')
        else:
            return self.cleaned_data['username']

    def clean_email(self):
        if User.objects.filter(email__iexact=self.cleaned_data['email']):
            raise forms.ValidationError(
                'This email address is already in use. Please supply a different email address.'
                )
        return self.cleaned_data['email']

    def clean(self):
        if ('password1' in self.cleaned_data and 'password2' in self.
            cleaned_data):
            if self.cleaned_data['password1'] != self.cleaned_data['password2'
                ]:
                raise forms.ValidationError(
                    "The two password fields didn't match.")
        return self.cleaned_data

<mask token>


class CreateUserForm(forms.Form):
    required_css_class = 'required'
    username = forms.RegexField(regex='^[\\w.@+-]+$', max_length=30, label=
        'Username', error_messages={'invalid':
        'This value may contain only letters, numbers and @/./+/-/_ characters.'
        })
    email = forms.EmailField(label='E-mail')
    password1 = forms.CharField(widget=forms.PasswordInput, label='Password')
    password2 = forms.CharField(widget=forms.PasswordInput, label=
        'Password (again)')

    def clean_username(self):
        existing = User.objects.filter(username__iexact=self.cleaned_data[
            'username'])
        if existing.exists():
            raise forms.ValidationError(
                'A user with that username already exists.')
        else:
            return self.cleaned_data['username']

    def clean_email(self):
        if User.objects.filter(email__iexact=self.cleaned_data['email']):
            raise forms.ValidationError(
                'This email address is already in use. Please supply a different email address.'
                )
        return self.cleaned_data['email']

    def clean(self):
        if ('password1' in self.cleaned_data and 'password2' in self.
            cleaned_data):
            if self.cleaned_data['password1'] != self.cleaned_data['password2'
                ]:
                raise forms.ValidationError(
                    "The two password fields didn't match.")
        return self.cleaned_data

from django import forms
from django.contrib.auth.models import User


class CreateUserForm(forms.Form):
    required_css_class = 'required'
    username = forms.RegexField(regex='^[\\w.@+-]+$', max_length=30, label=
        'Username', error_messages={'invalid':
        'This value may contain only letters, numbers and @/./+/-/_ characters.'
        })
    email = forms.EmailField(label='E-mail')
    password1 = forms.CharField(widget=forms.PasswordInput, label='Password')
    password2 = forms.CharField(widget=forms.PasswordInput, label=
        'Password (again)')

    def clean_username(self):
        existing = User.objects.filter(username__iexact=self.cleaned_data[
            'username'])
        if existing.exists():
            raise forms.ValidationError(
                'A user with that username already exists.')
        else:
            return self.cleaned_data['username']

    def clean_email(self):
        if User.objects.filter(email__iexact=self.cleaned_data['email']):
            raise forms.ValidationError(
                'This email address is already in use. Please supply a different email address.'
                )
        return self.cleaned_data['email']

    def clean(self):
        if ('password1' in self.cleaned_data and 'password2' in self.
            cleaned_data):
            if self.cleaned_data['password1'] != self.cleaned_data['password2'
                ]:
                raise forms.ValidationError(
                    "The two password fields didn't match.")
        return self.cleaned_data

from django import forms
from django.contrib.auth.models import User

class CreateUserForm(forms.Form):
    required_css_class = 'required'
    username = forms.RegexField(regex=r'^[\w.@+-]+$',
                                max_length=30,
                                label="Username",
                                error_messages={'invalid': "This value may contain only letters, numbers and @/./+/-/_ characters."})
    email = forms.EmailField(label="E-mail")
    password1 = forms.CharField(widget=forms.PasswordInput,
                                label="Password")
    password2 = forms.CharField(widget=forms.PasswordInput,
                                label="Password (again)")

    def clean_username(self):
        existing = User.objects.filter(username__iexact=self.cleaned_data['username'])
        if existing.exists():
            raise forms.ValidationError("A user with that username already exists.")
        else:
            return self.cleaned_data['username']

    def clean_email(self):
        #if you want unique email address. else delete this function
        if User.objects.filter(email__iexact=self.cleaned_data['email']):
            raise forms.ValidationError("This email address is already in use. Please supply a different email address.")
        return self.cleaned_data['email']

    def clean(self):
        if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
            if self.cleaned_data['password1'] != self.cleaned_data['password2']:
                raise forms.ValidationError("The two password fields didn't match.")
        return self.cleaned_data