diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 4d52f496b..689e2fe8d 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -171,6 +171,12 @@ class TagSerializer(MatchingModelSerializer): "document_count" ) + def validate_color(self, color): + regex = r"#[0-9a-fA-F]{6}" + if not re.match(regex, color): + raise serializers.ValidationError(_("Invalid color.")) + return color + class CorrespondentField(serializers.PrimaryKeyRelatedField): def get_queryset(self):