Skip to content

Commit

Permalink
Use RegexValidator for JabberFormField
Browse files Browse the repository at this point in the history
  • Loading branch information
chris34 committed Dec 4, 2023
1 parent aacb157 commit 3a11ee3
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions inyoka/utils/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,13 @@ class JabberFormField(forms.CharField):
# That way we don't need to validate the domain and resid.
_jabber_re = re.compile(r'(?xi)(?:[a-z0-9!$\(\)*+,;=\[\\\]\^`{|}\-._~]+)@')

def _may_be_valid_jabber(self, jabber):
return self._jabber_re.match(jabber) is not None

def clean(self, value):
value = super().clean(value)

if not self._may_be_valid_jabber(value):
raise forms.ValidationError(_('The entered Jabber address is invalid. '
'Please check your input.'))
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

return value
self.validators.append(
validators.RegexValidator(regex=self._jabber_re, message=_('The entered Jabber address is invalid. '
'Please check your input.'))
)


class SlugField(forms.CharField):
Expand Down

0 comments on commit 3a11ee3

Please sign in to comment.