Create Custom Validation for Django Form Input
Here is the forms.py file to write an example custom validator that ensures input text starts with 'Z' or 'z'.
Here is the forms.py file to write an example custom validator that ensures input text starts with 'Z' or 'z'.
from django import forms from django.core import validators def check_initial_z(value): if value[0].lower() != 'z': raise forms.ValidationError("Name needs to start with Z") class FormName(forms.Form): name = forms.CharField(validators=[check_initial_z]) email = forms.EmailField() text = forms.CharField(widget=forms.Textarea)
Comments
Post a Comment