mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-07 11:53:52 -05:00
don't allow commas in placeholder fields
This commit is contained in:
@@ -50,6 +50,7 @@ from app.main.validators import (
|
||||
CommonlyUsedPassword,
|
||||
CsvFileValidator,
|
||||
DoesNotStartWithDoubleZero,
|
||||
FieldCannotContainComma,
|
||||
LettersNumbersSingleQuotesFullStopsAndUnderscoresOnly,
|
||||
MustContainAlphanumericCharacters,
|
||||
NoCommasInPlaceHolders,
|
||||
@@ -1650,7 +1651,11 @@ def get_placeholder_form_instance(
|
||||
) # TODO: replace with us_mobile_number
|
||||
else:
|
||||
field = GovukTextInputField(
|
||||
placeholder_name, validators=[DataRequired(message="Cannot be empty")]
|
||||
placeholder_name,
|
||||
validators=[
|
||||
DataRequired(message="Cannot be empty"),
|
||||
FieldCannotContainComma(),
|
||||
],
|
||||
)
|
||||
|
||||
PlaceholderForm.placeholder_value = field
|
||||
|
||||
@@ -161,6 +161,15 @@ class DoesNotStartWithDoubleZero:
|
||||
raise ValidationError(self.message)
|
||||
|
||||
|
||||
class FieldCannotContainComma:
|
||||
def __init__(self, message="Cannot contain a comma"):
|
||||
self.message = message
|
||||
|
||||
def __call__(self, form, field):
|
||||
if field.data and "," in field.data:
|
||||
raise ValidationError(self.message)
|
||||
|
||||
|
||||
class MustContainAlphanumericCharacters:
|
||||
regex = re.compile(r".*[a-zA-Z0-9].*[a-zA-Z0-9].*")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user