From 47fa66cba3c6085bbf634bb86b6554d6e90a14bf Mon Sep 17 00:00:00 2001 From: Matthew Phelan Date: Thu, 7 Oct 2021 12:41:53 +0100 Subject: [PATCH] regex validation added --- app/models/case_log.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index d56dba600..4933c7483 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -3,10 +3,8 @@ class CaseLogValidator < ActiveModel::Validator def validate_tenant_age(record) if !record.tenant_age? record.errors.add :base, "Tenant age can't be blank" - elsif record.tenant_age < 0 - record.errors.add :base, "Age needs to be above 0" - elsif record.tenant_age > 120 - record.errors.add :base, "Age needs to be below 120" + elsif !(record.tenant_age.to_s =~ /^[1-9][0-9]?$|^100$/) + record.errors.add :base, "Tenant age must be between 0 and 100" end end