diff --git a/boards/forms.py b/boards/forms.py --- a/boards/forms.py +++ b/boards/forms.py @@ -1,3 +1,4 @@ +import re from django import forms from neboard import settings @@ -38,17 +39,17 @@ class PostForm(forms.Form): class ThreadForm(PostForm): - INVALID_TAG_CHARACTERS = ['+', '/', '&', '=', '?', '-', '.', ','] + regex_tags = re.compile(r'^[\w\s]+$') tags = forms.CharField(max_length=100) def clean_tags(self): tags = self.cleaned_data['tags'] + if tags: - for character in tags: - if character in self.INVALID_TAG_CHARACTERS: - raise forms.ValidationError( - 'Inappropriate characters in tags') + if not self.regex_tags.match(tags): + raise forms.ValidationError( + 'Inappropriate characters in tags') return tags