1π
It is always safer and recommended to use the build-in email validator that comes with Django.
You have not put blank=True and null=True while declaring email. So, Django will always make sure that this field is never blank/null. Django will also make sure that only valid email address is entered by user. As a matter of fact, you need not do anything else.
email = forms.EmailField(max_length=50, widget=forms.EmailInput, label="Email")
Reference: https://docs.djangoproject.com/en/3.2/ref/forms/fields/#django.forms.Field.clean
0π
if you want to modify email address in Django forms
email_user_part_regex = re.compile(
r"^(?=.{4,30}$)[\w\u0080-\uffff]+(?:[\.\-+][\w\u0080-\uffff]+)*$",
re.IGNORECASE | re.UNICODE,
)
class ForgetPasswordEmailForm(forms.Form):
email = forms.EmailField(label='email', max_length=200)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
validate_email.user_regex = email_user_part_regex
π€achu prasad
- [Answered ]-How to limit choices to Foreign keys in Django admin
- [Answered ]-How to fix Network is unreachable with django's send_mail?
- [Answered ]-How to make a Model with a Many-to-Many relationship as Categories (i.e) rock ,Country, Blues, and Pop
- [Answered ]-Downloading archives response corrupts files
- [Answered ]-Django/AngularJS: CSFR Token Error
Source:stackexchange.com