[Answer]-Django RegexValidator Not working as expected

1👍

✅

Do your own validator and if the regexp matches throw an error since it shouldn’t be allowed.
here more info about validator.

import re
from django.core.exceptions import ValidationError

def test(val):
    if re.match('<\/?(?!p|ul|li)[^/>]*>', val):
        raise ValidationError('Disallowed Tags')

class Foo(models.Model):
    name = models.CharField(max_length = 150, validators=[test]) 

Leave a comment