Skip to content

Commit b4e18e6

Browse files
authored
Merge pull request #3404 from TechnologyEnhancedLearning/revert-3355-Develop/Features/TD-4624-Addregexvalidationofprofessionalregistrationnumberfieldthroughouttheapplication
Revert "TD-4624 Add regex validation of professional registration number field throughout the application"
2 parents 15d5db4 + 424a786 commit b4e18e6

File tree

5 files changed

+23
-36
lines changed

5 files changed

+23
-36
lines changed

DigitalLearningSolutions.Web.Tests/Controllers/Register/RegisterDelegateByCentreControllerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void LearnerInformationPost_updates_tempdata_correctly()
176176
const string answer4 = "answer4";
177177
const string answer5 = "answer5";
178178
const string answer6 = "answer6";
179-
const string professionalRegistrationNumber = "PR123456";
179+
const string professionalRegistrationNumber = "PRN1234";
180180
var model = new LearnerInformationViewModel
181181
{
182182
JobGroup = jobGroupId,

DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Delegates/EditDelegateControllerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void Index_post_returns_view_with_model_error_with_invalid_prn()
175175
result.As<ViewResult>().Model.Should().BeOfType<EditDelegateViewModel>();
176176
AssertModelStateErrorIsExpected(
177177
result,
178-
ErrorMessagesTestHelper.InvalidFormatError
178+
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
179179
);
180180
A.CallTo(() => userService.GetDelegateById(A<int>._)).MustNotHaveHappened();
181181
}

DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
namespace DigitalLearningSolutions.Web.Tests.Helpers
22
{
3+
using System.Linq;
34
using DigitalLearningSolutions.Web.Helpers;
4-
using DigitalLearningSolutions.Web.Tests.TestHelpers;
55
using FluentAssertions;
66
using FluentAssertions.Execution;
77
using Microsoft.AspNetCore.Mvc.ModelBinding;
88
using NUnit.Framework;
9-
using System.Linq;
109

1110
public class ProfessionalRegistrationNumberHelperTests
1211
{
@@ -71,7 +70,7 @@ public void ValidateProfessionalRegistrationNumber_does_not_set_errors_when_vali
7170
{
7271
// Given
7372
var state = new ModelStateDictionary();
74-
const string validPrn = "AB123456";
73+
const string validPrn = "abc-123";
7574

7675
// When
7776
ProfessionalRegistrationNumberHelper.ValidateProfessionalRegistrationNumber(
@@ -105,13 +104,22 @@ public void ValidateProfessionalRegistrationNumber_sets_error_when_hasPrn_is_not
105104
}
106105
}
107106

108-
[TestCase(null, ErrorMessagesTestHelper.MissingNumberError)]
109-
[TestCase("", ErrorMessagesTestHelper.MissingNumberError)]
110-
[TestCase("1234", ErrorMessagesTestHelper.LengthError)]
111-
[TestCase("1234", ErrorMessagesTestHelper.LengthError)]
112-
[TestCase("01234_", ErrorMessagesTestHelper.InvalidFormatError)]
113-
[TestCase("01234 ", ErrorMessagesTestHelper.InvalidFormatError)]
114-
[TestCase("01234$", ErrorMessagesTestHelper.InvalidFormatError)]
107+
[TestCase(null, "Enter a professional registration number")]
108+
[TestCase("", "Enter a professional registration number")]
109+
[TestCase("123", "Professional registration number must be between 5 and 20 characters")]
110+
[TestCase("0123456789-0123456789", "Professional registration number must be between 5 and 20 characters")]
111+
[TestCase(
112+
"01234_",
113+
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
114+
)]
115+
[TestCase(
116+
"01234 ",
117+
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
118+
)]
119+
[TestCase(
120+
"01234$",
121+
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
122+
)]
115123
public void ValidateProfessionalRegistrationNumber_sets_error_when_prn_is_invalid(
116124
string prn,
117125
string expectedError

DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace DigitalLearningSolutions.Web.Helpers
22
{
3-
using Microsoft.AspNetCore.Mvc.ModelBinding;
43
using System.Text.RegularExpressions;
4+
using Microsoft.AspNetCore.Mvc.ModelBinding;
55

66
public class ProfessionalRegistrationNumberHelper
77
{
@@ -48,17 +48,13 @@ public static void ValidateProfessionalRegistrationNumber(
4848
);
4949
}
5050

51-
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})$";
51+
const string pattern = @"^[a-z\d-]+$";
5252
var rg = new Regex(pattern, RegexOptions.IgnoreCase);
5353
if (!rg.Match(prn).Success)
5454
{
5555
modelState.AddModelError(
5656
"ProfessionalRegistrationNumber",
57-
"Invalid professional registration number format. " +
58-
"Valid formats include: 7 digits (e.g., 1234567), 1–2 letters followed by 6 digits (e.g., AB123456), " +
59-
"4–8 digits, an optional 'P' plus 5–6 digits, 'C' or 'P' plus 6 digits, " +
60-
"an optional letter plus 5–6 digits, 'L' plus 4–6 digits, " +
61-
"or 2 digits followed by a hyphen and 4–5 alphanumeric characters (e.g., 12-AB123)."
57+
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
6258
);
6359
}
6460
}

0 commit comments

Comments
 (0)