diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index ccac2700b..022a5f038 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -164,7 +164,7 @@ module Validations::SoftValidations ].freeze def reasonother_might_be_existing_category? - Regexp.union(PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY.map { |phrase| Regexp.new("\\b#{phrase}\\b", Regexp::IGNORECASE) }).match?(reasonother) + Regexp.union(PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY.map { |phrase| Regexp.new("\\b[^[:alpha]]*#{phrase}[^[:alpha:]]*\\b", Regexp::IGNORECASE) }).match?(reasonother) end private diff --git a/spec/models/validations/soft_validations_spec.rb b/spec/models/validations/soft_validations_spec.rb index cd3a35235..ad87b3c5b 100644 --- a/spec/models/validations/soft_validations_spec.rb +++ b/spec/models/validations/soft_validations_spec.rb @@ -1048,5 +1048,11 @@ RSpec.describe Validations::SoftValidations do expect(record).not_to be_reasonother_might_be_existing_category end + + it "ignores neighbouring non-alphabet for matching" do + record.reasonother = "1Domestic abuse." + + expect(record).to be_reasonother_might_be_existing_category + end end end