mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
email: aliases: Minor refactoring to form validation
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
3d15ebd436
commit
a5a3500630
@ -38,13 +38,14 @@ class AliasCreateForm(forms.Form):
|
|||||||
def clean_alias(self):
|
def clean_alias(self):
|
||||||
"""Return the checked value for alias."""
|
"""Return the checked value for alias."""
|
||||||
value = self.data['alias'].strip().lower()
|
value = self.data['alias'].strip().lower()
|
||||||
if not re.match('^[a-z0-9-_\\.]+$', value):
|
if not re.match(r'^[a-z0-9-_\.]+$', value):
|
||||||
raise ValidationError(_('Contains illegal characters'))
|
raise ValidationError(_('Contains illegal characters'))
|
||||||
|
|
||||||
if not re.match('^[a-z0-9].*[a-z0-9]$', value):
|
if not re.match(r'^[a-z0-9].*[a-z0-9]$', value):
|
||||||
raise ValidationError(_('Must start and end with a-z or 0-9'))
|
raise ValidationError(_('Must start and end with a-z or 0-9'))
|
||||||
|
|
||||||
if re.match('^[0-9]+$', value):
|
# For when uids are automatically aliased to username
|
||||||
|
if re.match(r'^[0-9]+$', value):
|
||||||
raise ValidationError(_('Cannot be a number'))
|
raise ValidationError(_('Cannot be a number'))
|
||||||
|
|
||||||
if aliases_module.exists(value):
|
if aliases_module.exists(value):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user