Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = "PR123456";
const string professionalRegistrationNumber = "PRN1234";
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,
ErrorMessagesTestHelper.InvalidFormatError
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
);
A.CallTo(() => userService.GetDelegateById(A<int>._)).MustNotHaveHappened();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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 @@ -71,7 +70,7 @@ public void ValidateProfessionalRegistrationNumber_does_not_set_errors_when_vali
{
// Given
var state = new ModelStateDictionary();
const string validPrn = "AB123456";
const string validPrn = "abc-123";

// When
ProfessionalRegistrationNumberHelper.ValidateProfessionalRegistrationNumber(
Expand Down Expand Up @@ -105,13 +104,22 @@ 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)]
[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"
)]
public void ValidateProfessionalRegistrationNumber_sets_error_when_prn_is_invalid(
string prn,
string expectedError
Expand Down

This file was deleted.

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

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

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