diff --git a/app/main/forms.py b/app/main/forms.py index afec80f9f..90a4409fc 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -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 diff --git a/app/main/validators.py b/app/main/validators.py index 4dd04017b..1dfc97c48 100644 --- a/app/main/validators.py +++ b/app/main/validators.py @@ -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].*")