Hi,
I'd like to validate user input with regular expression in Django Admin CharField... How is it possible?
Thanks in advance, Etam.
Hi,
I'd like to validate user input with regular expression in Django Admin CharField... How is it possible?
Thanks in advance, Etam.
Define a custom form for your model admin, and override the specific field to use a RegexField
.
class MyModel(models.Model):
myfield = models.CharField(max_length=10)
class MyModelForm(forms.ModelForm):
myfield = forms.RegexField(regex=r'\w+')
class MyModelAdmin(admin.ModelAdmin):
form = MyModelForm
admin.site.register(MyModel, MyModelAdmin)
You can also use clean method in ur form and validiate the fields using regex.That will form validiation.You can raise error on what u want