mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 08:16:51 -04:00
Merge pull request #3179 from alphagov/validate-service-and-org-name
Validate service and organisation name
This commit is contained in:
@@ -40,6 +40,7 @@ from app.main.validators import (
|
||||
CsvFileValidator,
|
||||
DoesNotStartWithDoubleZero,
|
||||
LettersNumbersAndFullStopsOnly,
|
||||
MustContainAlphanumericCharacters,
|
||||
NoCommasInPlaceHolders,
|
||||
OnlySMSCharacters,
|
||||
ValidEmail,
|
||||
@@ -547,7 +548,8 @@ class RenameServiceForm(StripWhitespaceForm):
|
||||
name = StringField(
|
||||
u'Service name',
|
||||
validators=[
|
||||
DataRequired(message='Cannot be empty')
|
||||
DataRequired(message='Cannot be empty'),
|
||||
MustContainAlphanumericCharacters()
|
||||
])
|
||||
|
||||
|
||||
@@ -555,7 +557,8 @@ class RenameOrganisationForm(StripWhitespaceForm):
|
||||
name = StringField(
|
||||
u'Organisation name',
|
||||
validators=[
|
||||
DataRequired(message='Cannot be empty')
|
||||
DataRequired(message='Cannot be empty'),
|
||||
MustContainAlphanumericCharacters()
|
||||
])
|
||||
|
||||
|
||||
@@ -662,7 +665,8 @@ class CreateServiceForm(StripWhitespaceForm):
|
||||
name = StringField(
|
||||
"What’s your service called?",
|
||||
validators=[
|
||||
DataRequired(message='Cannot be empty')
|
||||
DataRequired(message='Cannot be empty'),
|
||||
MustContainAlphanumericCharacters()
|
||||
])
|
||||
organisation_type = OrganisationTypeField('Who runs this service?')
|
||||
|
||||
|
||||
@@ -111,3 +111,18 @@ class DoesNotStartWithDoubleZero:
|
||||
def __call__(self, form, field):
|
||||
if field.data and field.data.startswith("00"):
|
||||
raise ValidationError(self.message)
|
||||
|
||||
|
||||
class MustContainAlphanumericCharacters:
|
||||
|
||||
regex = re.compile(r".*[a-zA-Z0-9].*[a-zA-Z0-9].*")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
message="Must include at least two alphanumeric characters"
|
||||
):
|
||||
self.message = message
|
||||
|
||||
def __call__(self, form, field):
|
||||
if field.data and not re.match(self.regex, field.data):
|
||||
raise ValidationError(self.message)
|
||||
|
||||
Reference in New Issue
Block a user