Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void LearnerInformationPost_updates_tempdata_correctly()
const string answer4 = "answer4";
const string answer5 = "answer5";
const string answer6 = "answer6";
const string professionalRegistrationNumber = "PRN1234";
const string professionalRegistrationNumber = "PR123456";
var model = new LearnerInformationViewModel
{
JobGroup = jobGroupId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void Index_post_returns_view_with_model_error_with_invalid_prn()
result.As<ViewResult>().Model.Should().BeOfType<EditDelegateViewModel>();
AssertModelStateErrorIsExpected(
result,
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
ErrorMessagesTestHelper.InvalidFormatError
);
A.CallTo(() => userService.GetDelegateById(A<int>._)).MustNotHaveHappened();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace DigitalLearningSolutions.Web.Tests.Helpers
{
using System.Linq;
using DigitalLearningSolutions.Web.Helpers;
using DigitalLearningSolutions.Web.Tests.TestHelpers;
using FluentAssertions;
using FluentAssertions.Execution;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using NUnit.Framework;
using System.Linq;

public class ProfessionalRegistrationNumberHelperTests
{
Expand Down Expand Up @@ -70,7 +71,7 @@ public void ValidateProfessionalRegistrationNumber_does_not_set_errors_when_vali
{
// Given
var state = new ModelStateDictionary();
const string validPrn = "abc-123";
const string validPrn = "AB123456";

// When
ProfessionalRegistrationNumberHelper.ValidateProfessionalRegistrationNumber(
Expand Down Expand Up @@ -104,22 +105,13 @@ public void ValidateProfessionalRegistrationNumber_sets_error_when_hasPrn_is_not
}
}

[TestCase(null, "Enter a professional registration number")]
[TestCase("", "Enter a professional registration number")]
[TestCase("123", "Professional registration number must be between 5 and 20 characters")]
[TestCase("0123456789-0123456789", "Professional registration number must be between 5 and 20 characters")]
[TestCase(
"01234_",
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
)]
[TestCase(
"01234 ",
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
)]
[TestCase(
"01234$",
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
)]
[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)]
public void ValidateProfessionalRegistrationNumber_sets_error_when_prn_is_invalid(
string prn,
string expectedError
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

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).";

public const string MissingNumberError = "Enter a professional registration number";
public const string LengthError = "Professional registration number must be between 5 and 20 characters";

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace DigitalLearningSolutions.Web.Helpers
{
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using System.Text.RegularExpressions;

public class ProfessionalRegistrationNumberHelper
{
Expand Down Expand Up @@ -48,13 +48,17 @@ public static void ValidateProfessionalRegistrationNumber(
);
}

const string pattern = @"^[a-z\d-]+$";
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 - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
"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)."
);
}
}
Expand Down
Loading