##// END OF EJS Templates
Added a regex for validation of tags. This refs #10
neko259 -
r69:dd7c561f default
parent child Browse files
Show More
@@ -1,3 +1,4 b''
1 import re
1 from django import forms
2 from django import forms
2 from neboard import settings
3 from neboard import settings
3
4
@@ -38,17 +39,17 b' class PostForm(forms.Form):'
38
39
39
40
40 class ThreadForm(PostForm):
41 class ThreadForm(PostForm):
41 INVALID_TAG_CHARACTERS = ['+', '/', '&', '=', '?', '-', '.', ',']
42 regex_tags = re.compile(r'^[\w\s]+$')
42
43
43 tags = forms.CharField(max_length=100)
44 tags = forms.CharField(max_length=100)
44
45
45 def clean_tags(self):
46 def clean_tags(self):
46 tags = self.cleaned_data['tags']
47 tags = self.cleaned_data['tags']
48
47 if tags:
49 if tags:
48 for character in tags:
50 if not self.regex_tags.match(tags):
49 if character in self.INVALID_TAG_CHARACTERS:
51 raise forms.ValidationError(
50 raise forms.ValidationError(
52 'Inappropriate characters in tags')
51 'Inappropriate characters in tags')
52
53
53 return tags
54 return tags
54
55
General Comments 0
You need to be logged in to leave comments. Login now