Skip to content

Commit

Permalink
Add missing special characters to name format regex
Browse files Browse the repository at this point in the history
  • Loading branch information
AbigailMcP committed Aug 15, 2024
1 parent 1f53ca4 commit 8a233b4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/name_format_validator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class NameFormatValidator < ActiveModel::EachValidator
NAME_REGEX_FILTER = /\A[^"=$%#&*+\/\\()@?!<>0-9]*\z/
NAME_REGEX_FILTER = /\A[^\[\]\^"=$%#&*+\/\\()@?!<>_`|{}~0-9]*\z/

def validate_each(record, attribute, value)
return unless value.present?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
# First name validations
it { should validate_presence_of(:first_name).with_message("Enter employee’s first name") }
it { should validate_length_of(:first_name).is_at_most(100).with_message("Employee’s first name must be less than 100 characters") }
it { should_not allow_value("*").for(:first_name).with_message("Employee’s first name cannot contain special characters") }
it { should allow_value("O'Brian").for(:first_name) }
%w[* | { ^ /].each do |char|
it { should_not allow_value(char).for(:first_name).with_message("Employee’s first name cannot contain special characters") }
end

# Surname validations
it { should validate_presence_of(:surname).with_message("Enter employee’s last name") }
it { should validate_length_of(:surname).is_at_most(100).with_message("Employee’s last name must be less than 100 characters") }
it { should_not allow_value("$").for(:surname).with_message("Employee’s last name cannot contain special characters") }
it { should_not allow_value("5").for(:surname).with_message("Employee’s last name cannot contain special characters") }
it { should allow_value("O'Brian").for(:surname) }
end

Expand Down

0 comments on commit 8a233b4

Please sign in to comment.