# HG changeset patch # User neko259 # Date 2013-06-04 19:12:44 # Node ID dd7c561f50566256e9abdcb9e9ab266f7e2d3c08 # Parent ae7793c6bf33804eac5923478ec5b66af01457b9 Added a regex for validation of tags. This refs #10 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