diff --git a/app/models/name_format_validator.rb b/app/models/name_format_validator.rb index 1fb21104e..e8426cc61 100644 --- a/app/models/name_format_validator.rb +++ b/app/models/name_format_validator.rb @@ -1,10 +1,11 @@ class NameFormatValidator < ActiveModel::EachValidator NAME_REGEX_FILTER = /\A[^\[\]\^"=$%#&*+\/\\()@?!<>_`|{}~0-9]*\z/ + HAS_LETTERS_FILTER = /[a-zA-Z]/ def validate_each(record, attribute, value) return unless value.present? - unless NAME_REGEX_FILTER.match?(value) + unless NAME_REGEX_FILTER.match?(value) && HAS_LETTERS_FILTER.match?(value) record.errors.add(attribute, options[:message]) end end diff --git a/spec/forms/personal_details_form_spec.rb b/spec/forms/personal_details_form_spec.rb index ad4a4c59c..6b8341d74 100644 --- a/spec/forms/personal_details_form_spec.rb +++ b/spec/forms/personal_details_form_spec.rb @@ -271,6 +271,7 @@ it { should validate_length_of(:first_name).is_at_most(100).with_message("First name must be less than 100 characters") } it { should_not allow_value("*").for(:first_name).with_message("First name cannot contain special characters") } it { should allow_value("O'Brian").for(:first_name) } + it { should_not allow_value(".").for(:first_name) } it { should validate_length_of(:middle_name).is_at_most(61).with_message("Middle names must be less than 61 characters") } it { should_not allow_value("&").for(:middle_name).with_message("Middle names cannot contain special characters") } @@ -280,6 +281,7 @@ it { should validate_length_of(:surname).is_at_most(100).with_message("Last name must be less than 100 characters") } it { should_not allow_value("$").for(:surname).with_message("Last name cannot contain special characters") } it { should allow_value("O'Brian").for(:surname) } + it { should_not allow_value(".").for(:surname) } it { should validate_presence_of(:national_insurance_number).with_message("Enter a National Insurance number in the correct format") } it { should allow_value("QQ123456C").for(:national_insurance_number) }