From f13f2e98bf1e46af120c6e67b0a75d03bf8b12ae Mon Sep 17 00:00:00 2001 From: sherif-olaboye <123654949+sherif-olaboye@users.noreply.github.com> Date: Mon, 29 Sep 2025 15:48:39 +0100 Subject: [PATCH 1/5] TD-4624 Refactor the error message --- ...ofessionalRegistrationNumberHelperTests.cs | 2 -- .../TestHelpers/ErrorMessagesTestHelper.cs | 16 ++++++---- .../ProfessionalRegistrationNumberHelper.cs | 32 ++++++++++--------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs b/DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs index a7270f280d..d47a8eeb96 100644 --- a/DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs +++ b/DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs @@ -107,8 +107,6 @@ public void ValidateProfessionalRegistrationNumber_sets_error_when_hasPrn_is_not [TestCase(null, ErrorMessagesTestHelper.MissingNumberError)] [TestCase("", ErrorMessagesTestHelper.MissingNumberError)] - [TestCase("1234", ErrorMessagesTestHelper.LengthError)] - [TestCase("1234", ErrorMessagesTestHelper.LengthError)] [TestCase("01234_", ErrorMessagesTestHelper.InvalidFormatError)] [TestCase("01234 ", ErrorMessagesTestHelper.InvalidFormatError)] [TestCase("01234$", ErrorMessagesTestHelper.InvalidFormatError)] diff --git a/DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs b/DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs index 7636944e7a..9f5cdbf98b 100644 --- a/DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs +++ b/DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs @@ -4,14 +4,18 @@ namespace DigitalLearningSolutions.Web.Tests.TestHelpers public static class ErrorMessagesTestHelper { public const string InvalidFormatError = - "Invalid professional registration number format. " + - "Valid formats include: 7 digits (e.g., 1234567), 1–2 letters followed by 6 digits (e.g., AB123456), " + - "4–8 digits, an optional 'P' plus 5–6 digits, 'C' or 'P' plus 6 digits, " + - "an optional letter plus 5–6 digits, 'L' plus 4–6 digits, " + - "or 2 digits followed by a hyphen and 4–5 alphanumeric characters (e.g., 12-AB123)."; + @"The format you entered isn’t recognised. Please check and try again. + Valid formats include + 7 digits - example, 1234567 + 1-2 letters followed by 6 digits - example, AB123456 + ‘P’ followed by 5-6 digits - example, P12345, P123456 + ‘C’ or ‘P’ followed by 6 digits - example, C123456, P123456 + Optional letter followed by 5-6 digits - example, A12345, B123456 + ‘L’ followed by 4-6 digits - example, L1234, L123456 + 2 digits, hyphen, then 4-5 alphanumeric characters - example, 12-AB123"; public const string MissingNumberError = "Enter a professional registration number"; - public const string LengthError = "Professional registration number must be between 5 and 20 characters"; + public const string LengthError = "Professional registration number must be between 4 and 8 characters"; } } diff --git a/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs b/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs index 130c8d52b6..1f6a2036c5 100644 --- a/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs +++ b/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs @@ -1,6 +1,9 @@ namespace DigitalLearningSolutions.Web.Helpers { + using DocumentFormat.OpenXml.Spreadsheet; using Microsoft.AspNetCore.Mvc.ModelBinding; + using MimeKit; + using System; using System.Text.RegularExpressions; public class ProfessionalRegistrationNumberHelper @@ -39,28 +42,27 @@ public static void ValidateProfessionalRegistrationNumber( modelState.AddModelError("ProfessionalRegistrationNumber", "Enter a professional registration number"); return; } - - if (prn.Length < 5 || prn.Length > 20) - { - modelState.AddModelError( - "ProfessionalRegistrationNumber", - "Professional registration number must be between 5 and 20 characters" - ); - } - - const string pattern = @"^(\d{7}|[A-Za-z]{1,2}\d{6}|\d{4,8}|P?\d{5,6}|[C|P]\d{6}|[A-Za-z]?\d{5,6}|L\d{4,6}|\d{2}-[A-Za-z\d]{4,5})$"; + const string pattern = @"^(\d{7}|[A-Za-z]{1,2}\d{6}|\d{4,8}|P?\d{5,6}|[C|P]\d{6}|[A-Za-z]?\d{5,6}|L\d{4,6}|\d{2}-[A-Za-z\d]{4,5})$"; var rg = new Regex(pattern, RegexOptions.IgnoreCase); if (!rg.Match(prn).Success) { modelState.AddModelError( "ProfessionalRegistrationNumber", - "Invalid professional registration number format. " + - "Valid formats include: 7 digits (e.g., 1234567), 1–2 letters followed by 6 digits (e.g., AB123456), " + - "4–8 digits, an optional 'P' plus 5–6 digits, 'C' or 'P' plus 6 digits, " + - "an optional letter plus 5–6 digits, 'L' plus 4–6 digits, " + - "or 2 digits followed by a hyphen and 4–5 alphanumeric characters (e.g., 12-AB123)." + GetProfessionalRegistrationNumberErrorMessage() ); } } + public static string GetProfessionalRegistrationNumberErrorMessage() + { + return @"The format you entered isn’t recognised. Please check and try again. + Valid formats include + 7 digits - example, 1234567 + 1-2 letters followed by 6 digits - example, AB123456 + ‘P’ followed by 5-6 digits - example, P12345, P123456 + ‘C’ or ‘P’ followed by 6 digits - example, C123456, P123456 + Optional letter followed by 5-6 digits - example, A12345, B123456 + ‘L’ followed by 4-6 digits - example, L1234, L123456 + 2 digits, hyphen, then 4-5 alphanumeric characters - example, 12-AB123"; + } } } From 4f653d97635bac1eeadc3cdd1bb6d2f0790d232e Mon Sep 17 00:00:00 2001 From: sherif-olaboye <123654949+sherif-olaboye@users.noreply.github.com> Date: Mon, 29 Sep 2025 17:08:39 +0100 Subject: [PATCH 2/5] TD-4624 Removed unneeded reference --- .../Helpers/ProfessionalRegistrationNumberHelper.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs b/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs index 1f6a2036c5..58718263be 100644 --- a/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs +++ b/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs @@ -1,9 +1,7 @@ namespace DigitalLearningSolutions.Web.Helpers { - using DocumentFormat.OpenXml.Spreadsheet; + using Microsoft.AspNetCore.Mvc.ModelBinding; - using MimeKit; - using System; using System.Text.RegularExpressions; public class ProfessionalRegistrationNumberHelper From 23c869ebcc020cfb617bf0673e367e7d116b0615 Mon Sep 17 00:00:00 2001 From: sherif-olaboye <123654949+sherif-olaboye@users.noreply.github.com> Date: Thu, 2 Oct 2025 10:55:59 +0100 Subject: [PATCH 3/5] TD-4624 format the error message --- .../ProfessionalRegistrationNumberHelper.cs | 19 +++++++++------- .../Shared/_EditRegistrationNumber.cshtml | 18 ++++++++++++--- .../Delegates/EditDelegate/Index.cshtml | 22 ++++++++++++++++++- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs b/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs index 58718263be..a667a1f597 100644 --- a/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs +++ b/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs @@ -2,6 +2,7 @@ { using Microsoft.AspNetCore.Mvc.ModelBinding; + using System.Text; using System.Text.RegularExpressions; public class ProfessionalRegistrationNumberHelper @@ -53,14 +54,16 @@ public static void ValidateProfessionalRegistrationNumber( public static string GetProfessionalRegistrationNumberErrorMessage() { return @"The format you entered isn’t recognised. Please check and try again. - Valid formats include - 7 digits - example, 1234567 - 1-2 letters followed by 6 digits - example, AB123456 - ‘P’ followed by 5-6 digits - example, P12345, P123456 - ‘C’ or ‘P’ followed by 6 digits - example, C123456, P123456 - Optional letter followed by 5-6 digits - example, A12345, B123456 - ‘L’ followed by 4-6 digits - example, L1234, L123456 - 2 digits, hyphen, then 4-5 alphanumeric characters - example, 12-AB123"; +
Valid formats include: + "; } } } diff --git a/DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml b/DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml index d50f11c819..f5710e6543 100644 --- a/DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml +++ b/DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml @@ -17,6 +17,11 @@ var subject = Model.IsSelfRegistrationOrEdit ? "you" : "they"; var capitalisedSubject = Model.IsSelfRegistrationOrEdit ? "You" : "They"; + var professionalRegistrationNumberError = ViewData.ModelState["ProfessionalRegistrationNumber"]?.Errors.FirstOrDefault()?.ErrorMessage; + if (ViewData.ModelState.ContainsKey("ProfessionalRegistrationNumber")) + { + ViewData.ModelState["ProfessionalRegistrationNumber"].Errors.Clear(); + } } @@ -53,7 +58,7 @@ No - +
-
- + Error: + @Html.Raw(professionalRegistrationNumberError) + + } + @if (errorHasOccurred) { - + } + if (professionalRegistrationNumberError != null) + { + + } }

Edit delegate details

From fca89d2a50dc17d84e55ca4455d68301d558409f Mon Sep 17 00:00:00 2001 From: sherif-olaboye <123654949+sherif-olaboye@users.noreply.github.com> Date: Thu, 2 Oct 2025 11:09:55 +0100 Subject: [PATCH 4/5] TD-4624 Fixing the test that is failing --- .../TestHelpers/ErrorMessagesTestHelper.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs b/DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs index 9f5cdbf98b..e72983a4a5 100644 --- a/DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs +++ b/DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs @@ -5,14 +5,16 @@ public static class ErrorMessagesTestHelper { public const string InvalidFormatError = @"The format you entered isn’t recognised. Please check and try again. - Valid formats include - 7 digits - example, 1234567 - 1-2 letters followed by 6 digits - example, AB123456 - ‘P’ followed by 5-6 digits - example, P12345, P123456 - ‘C’ or ‘P’ followed by 6 digits - example, C123456, P123456 - Optional letter followed by 5-6 digits - example, A12345, B123456 - ‘L’ followed by 4-6 digits - example, L1234, L123456 - 2 digits, hyphen, then 4-5 alphanumeric characters - example, 12-AB123"; +
Valid formats include: +
    +
  • 7 digits - example, 1234567
  • +
  • 1–2 letters followed by 6 digits - example, AB123456
  • +
  • ‘P’ followed by 5–6 digits - example, P12345, P123456
  • +
  • ‘C’ or ‘P’ followed by 6 digits - example, C123456, P123456
  • +
  • Optional letter followed by 5–6 digits - example, A12345, B123456
  • +
  • ‘L’ followed by 4–6 digits - example, L1234, L123456
  • +
  • 2 digits, hyphen, then 4–5 alphanumeric characters - example, 12-AB123
  • +
"; public const string MissingNumberError = "Enter a professional registration number"; public const string LengthError = "Professional registration number must be between 4 and 8 characters"; From 89780e5cebf276cd7b79177f9cf6e2e97c5b2e31 Mon Sep 17 00:00:00 2001 From: sherif-olaboye <123654949+sherif-olaboye@users.noreply.github.com> Date: Thu, 2 Oct 2025 11:17:10 +0100 Subject: [PATCH 5/5] TD-4624 Formating the error message --- .../Views/Shared/_EditRegistrationNumber.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml b/DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml index f5710e6543..d0ffd7d154 100644 --- a/DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml +++ b/DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml @@ -71,7 +71,7 @@ Yes
-
@if (professionalRegistrationNumberError != null) {