diff --git a/DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs b/DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs index d47a8eeb96..a7270f280d 100644 --- a/DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs +++ b/DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs @@ -107,6 +107,8 @@ 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 e72983a4a5..7636944e7a 100644 --- a/DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs +++ b/DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs @@ -4,20 +4,14 @@ namespace DigitalLearningSolutions.Web.Tests.TestHelpers public static class ErrorMessagesTestHelper { public const string InvalidFormatError = - @"The format you entered isn’t recognised. Please check and try again. -
Valid formats include: - "; + "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)."; public const string MissingNumberError = "Enter a professional registration number"; - public const string LengthError = "Professional registration number must be between 4 and 8 characters"; + public const string LengthError = "Professional registration number must be between 5 and 20 characters"; } } diff --git a/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs b/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs index a667a1f597..130c8d52b6 100644 --- a/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs +++ b/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs @@ -1,8 +1,6 @@ namespace DigitalLearningSolutions.Web.Helpers { - using Microsoft.AspNetCore.Mvc.ModelBinding; - using System.Text; using System.Text.RegularExpressions; public class ProfessionalRegistrationNumberHelper @@ -41,29 +39,28 @@ public static void ValidateProfessionalRegistrationNumber( modelState.AddModelError("ProfessionalRegistrationNumber", "Enter a professional registration number"); return; } - 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})$"; + + 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})$"; var rg = new Regex(pattern, RegexOptions.IgnoreCase); if (!rg.Match(prn).Success) { modelState.AddModelError( "ProfessionalRegistrationNumber", - GetProfessionalRegistrationNumberErrorMessage() + "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)." ); } } - public static string GetProfessionalRegistrationNumberErrorMessage() - { - return @"The format you entered isn’t recognised. Please check and try again. -
Valid formats include: - "; - } } } diff --git a/DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml b/DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml index d0ffd7d154..d50f11c819 100644 --- a/DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml +++ b/DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml @@ -17,11 +17,6 @@ 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(); - } } @@ -58,7 +53,7 @@ No - +
-
- @if (professionalRegistrationNumberError != null) - { - - Error: - @Html.Raw(professionalRegistrationNumberError) - - } - @if (errorHasOccurred) { - var professionalRegistrationNumberError = ViewData.ModelState["ProfessionalRegistrationNumber"]?.Errors.FirstOrDefault(); - if (professionalRegistrationNumberError == null) - { - - } - if (professionalRegistrationNumberError != null) - { - - } }

Edit delegate details