Skip to content

Commit 15d5db4

Browse files
authored
Merge pull request #3403 from TechnologyEnhancedLearning/revert-3387-Develop/Features/TD-4624-Addregexvalidationofprofessionalregistrationnumberfieldthroughouttheapplication
Revert "TD-4624 Add regex validation of professional registration number field throughout the application"
2 parents 1d171b1 + 240f13d commit 15d5db4

File tree

5 files changed

+27
-66
lines changed

5 files changed

+27
-66
lines changed

DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public void ValidateProfessionalRegistrationNumber_sets_error_when_hasPrn_is_not
107107

108108
[TestCase(null, ErrorMessagesTestHelper.MissingNumberError)]
109109
[TestCase("", ErrorMessagesTestHelper.MissingNumberError)]
110+
[TestCase("1234", ErrorMessagesTestHelper.LengthError)]
111+
[TestCase("1234", ErrorMessagesTestHelper.LengthError)]
110112
[TestCase("01234_", ErrorMessagesTestHelper.InvalidFormatError)]
111113
[TestCase("01234 ", ErrorMessagesTestHelper.InvalidFormatError)]
112114
[TestCase("01234$", ErrorMessagesTestHelper.InvalidFormatError)]

DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@ namespace DigitalLearningSolutions.Web.Tests.TestHelpers
44
public static class ErrorMessagesTestHelper
55
{
66
public const string InvalidFormatError =
7-
@"The format you entered isn’t recognised. Please check and try again.
8-
<br>Valid formats include:
9-
<ul>
10-
<li>7 digits - example, 1234567</li>
11-
<li>1–2 letters followed by 6 digits - example, AB123456</li>
12-
<li>‘P’ followed by 5–6 digits - example, P12345, P123456</li>
13-
<li>‘C’ or ‘P’ followed by 6 digits - example, C123456, P123456</li>
14-
<li>Optional letter followed by 5–6 digits - example, A12345, B123456</li>
15-
<li>‘L’ followed by 4–6 digits - example, L1234, L123456</li>
16-
<li>2 digits, hyphen, then 4–5 alphanumeric characters - example, 12-AB123</li>
17-
</ul>";
7+
"Invalid professional registration number format. " +
8+
"Valid formats include: 7 digits (e.g., 1234567), 1–2 letters followed by 6 digits (e.g., AB123456), " +
9+
"4–8 digits, an optional 'P' plus 5–6 digits, 'C' or 'P' plus 6 digits, " +
10+
"an optional letter plus 5–6 digits, 'L' plus 4–6 digits, " +
11+
"or 2 digits followed by a hyphen and 4–5 alphanumeric characters (e.g., 12-AB123).";
1812

1913
public const string MissingNumberError = "Enter a professional registration number";
20-
public const string LengthError = "Professional registration number must be between 4 and 8 characters";
14+
public const string LengthError = "Professional registration number must be between 5 and 20 characters";
2115

2216
}
2317
}

DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
namespace DigitalLearningSolutions.Web.Helpers
22
{
3-
43
using Microsoft.AspNetCore.Mvc.ModelBinding;
5-
using System.Text;
64
using System.Text.RegularExpressions;
75

86
public class ProfessionalRegistrationNumberHelper
@@ -41,29 +39,28 @@ public static void ValidateProfessionalRegistrationNumber(
4139
modelState.AddModelError("ProfessionalRegistrationNumber", "Enter a professional registration number");
4240
return;
4341
}
44-
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})$";
42+
43+
if (prn.Length < 5 || prn.Length > 20)
44+
{
45+
modelState.AddModelError(
46+
"ProfessionalRegistrationNumber",
47+
"Professional registration number must be between 5 and 20 characters"
48+
);
49+
}
50+
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})$";
4552
var rg = new Regex(pattern, RegexOptions.IgnoreCase);
4653
if (!rg.Match(prn).Success)
4754
{
4855
modelState.AddModelError(
4956
"ProfessionalRegistrationNumber",
50-
GetProfessionalRegistrationNumberErrorMessage()
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)."
5162
);
5263
}
5364
}
54-
public static string GetProfessionalRegistrationNumberErrorMessage()
55-
{
56-
return @"The format you entered isn’t recognised. Please check and try again.
57-
<br>Valid formats include:
58-
<ul>
59-
<li>7 digits - example, 1234567</li>
60-
<li>1–2 letters followed by 6 digits - example, AB123456</li>
61-
<li>‘P’ followed by 5–6 digits - example, P12345, P123456</li>
62-
<li>‘C’ or ‘P’ followed by 6 digits - example, C123456, P123456</li>
63-
<li>Optional letter followed by 5–6 digits - example, A12345, B123456</li>
64-
<li>‘L’ followed by 4–6 digits - example, L1234, L123456</li>
65-
<li>2 digits, hyphen, then 4–5 alphanumeric characters - example, 12-AB123</li>
66-
</ul>";
67-
}
6865
}
6966
}

DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717

1818
var subject = Model.IsSelfRegistrationOrEdit ? "you" : "they";
1919
var capitalisedSubject = Model.IsSelfRegistrationOrEdit ? "You" : "They";
20-
var professionalRegistrationNumberError = ViewData.ModelState["ProfessionalRegistrationNumber"]?.Errors.FirstOrDefault()?.ErrorMessage;
21-
if (ViewData.ModelState.ContainsKey("ProfessionalRegistrationNumber"))
22-
{
23-
ViewData.ModelState["ProfessionalRegistrationNumber"].Errors.Clear();
24-
}
2520
}
2621

2722
<input type="hidden" asp-for="IsSelfRegistrationOrEdit" />
@@ -58,7 +53,7 @@
5853
No
5954
</label>
6055
</div>
61-
56+
6257
<div class="nhsuk-radios__item">
6358
<input name="@nameof(Model.HasProfessionalRegistrationNumber)"
6459
class="nhsuk-radios__input"
@@ -71,16 +66,9 @@
7166
Yes
7267
</label>
7368
</div>
74-
<div class="nhsuk-radios__conditional"
69+
<div class="nhsuk-radios__conditional @(optionYesSelected ? " " : " nhsuk-radios__conditional--hidden") @(professionalRegNumberErrorHasOccurred ? "form-group-wrapper--error" : "" )"
7570
id="@professionalRegConditionalId">
76-
@if (professionalRegistrationNumberError != null)
77-
{
78-
<span class="nhsuk-error-message" id="ProfessionalRegistrationNumber-error">
79-
<span class="nhsuk-u-visually-hidden">Error:</span>
80-
@Html.Raw(professionalRegistrationNumberError)
81-
</span>
82-
}
83-
<vc:text-input asp-for="@nameof(Model.ProfessionalRegistrationNumber)"
71+
<vc:text-input asp-for="@nameof(Model.ProfessionalRegistrationNumber)"
8472
label="Professional Registration Number"
8573
populate-with-current-value="true"
8674
type="text"

DigitalLearningSolutions.Web/Views/TrackingSystem/Delegates/EditDelegate/Index.cshtml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
<div class="nhsuk-grid-column-full">
1616
@if (errorHasOccurred)
1717
{
18-
var professionalRegistrationNumberError = ViewData.ModelState["ProfessionalRegistrationNumber"]?.Errors.FirstOrDefault();
19-
if (professionalRegistrationNumberError == null)
20-
{
21-
<vc:error-summary order-of-property-names="@(new[] {
18+
<vc:error-summary order-of-property-names="@(new[] {
2219
nameof(Model.FirstName),
2320
nameof(Model.LastName),
2421
nameof(Model.CentreSpecificEmail),
@@ -31,23 +28,6 @@
3128
nameof(Model.Answer4),
3229
nameof(Model.Answer5),
3330
nameof(Model.Answer6) })" />
34-
}
35-
if (professionalRegistrationNumberError != null)
36-
{
37-
<div class="nhsuk-error-summary" aria-labelledby="error-summary-title" role="alert" tabindex="-1">
38-
<h2 class="nhsuk-error-summary__title" id="error-summary-title">
39-
There is a problem
40-
</h2>
41-
<div class="nhsuk-error-summary__body">
42-
<span class="nhsuk-error-message" id="ProfessionalRegistrationNumber-error">
43-
<span class="nhsuk-u-visually-hidden">Error:</span> <span class="nhsuk-error-message" id="ProfessionalRegistrationNumber-error">
44-
<span class="nhsuk-u-visually-hidden">Error:</span>
45-
@Html.Raw(professionalRegistrationNumberError.ErrorMessage)
46-
</span>
47-
</span>
48-
</div>
49-
</div>
50-
}
5131
}
5232

5333
<h1 class="nhsuk-heading-xl">Edit delegate details</h1>

0 commit comments

Comments
 (0)