Skip to content

Commit

Permalink
Merge pull request #3465 from DFE-Digital/CAPT-2063/dont-allow-dots-i…
Browse files Browse the repository at this point in the history
…n-claim-name-fields

Check name contains at least one letter
  • Loading branch information
rjlynch authored Dec 19, 2024
2 parents 4c91be0 + d948e12 commit f04c4b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/name_format_validator.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/forms/personal_details_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
Expand All @@ -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) }
Expand Down

0 comments on commit f04c4b2

Please sign in to comment.