I\'m a Django newbie.
I\'d like to restrict user to use a specific domain (e.g. @gmail.com ) to sign up my Django website, but how to customize the EmailField in my
You can write your own clean functions for the form:
class RegistrationForm(ModelForm):
username = forms.CharField(label=(u'User Name'))
email = forms.EmailField(label = (u'Email Adress'))
def clean_email(self):
data = self.cleaned_data['email']
if "@gmail.com" not in data: # any check you need
raise forms.ValidationError("Must be a gmail address")
return data
class Meta:
model = UserProfile
exclude = ('user',)
More at: https://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-a-specific-field-attribute