Skip to content

Commit e4edffc

Browse files
TD-4624 Add regex validation of professional registration number field throughout the application
1 parent 304cb3d commit e4edffc

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
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 = "PRN1234";
179+
const string professionalRegistrationNumber = "PR123456";
180180
var model = new LearnerInformationViewModel
181181
{
182182
JobGroup = jobGroupId,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ 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-
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
178+
"Invalid professional registration number format. Accepted formats are: 1–2 letters followed by 6 digits (e.g., AB123456)" +
179+
" 4–8 digits only " + "Optional ‘P’ followed by 5–6 digits ‘C’ or ‘P’ followed by 6 digits " +
180+
"Optional letter followed by 5–6 digits ‘L’ followed by 4–6 digits 2 digits, hyphen, then 4–5 alphanumeric characters"
181+
179182
);
180183
A.CallTo(() => userService.GetDelegateById(A<int>._)).MustNotHaveHappened();
181184
}

DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,28 @@ public void ValidateProfessionalRegistrationNumber_sets_error_when_hasPrn_is_not
106106

107107
[TestCase(null, "Enter a professional registration number")]
108108
[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")]
109+
[TestCase("1234", "Professional registration number must be between 5 and 20 characters")]
110+
[TestCase("1234", "Professional registration number must be between 5 and 20 characters")]
111111
[TestCase(
112112
"01234_",
113-
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
113+
"Invalid professional registration number format. Accepted formats are: 1–2 letters followed by 6 digits (e.g., AB123456)" +
114+
" 4–8 digits only " + "Optional ‘P’ followed by 5–6 digits ‘C’ or ‘P’ followed by 6 digits " +
115+
"Optional letter followed by 5–6 digits ‘L’ followed by 4–6 digits 2 digits, hyphen, then 4–5 alphanumeric characters"
116+
114117
)]
115118
[TestCase(
116119
"01234 ",
117-
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
120+
"Invalid professional registration number format. Accepted formats are: 1–2 letters followed by 6 digits (e.g., AB123456)" +
121+
" 4–8 digits only " + "Optional ‘P’ followed by 5–6 digits ‘C’ or ‘P’ followed by 6 digits " +
122+
"Optional letter followed by 5–6 digits ‘L’ followed by 4–6 digits 2 digits, hyphen, then 4–5 alphanumeric characters"
123+
118124
)]
119125
[TestCase(
120126
"01234$",
121-
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
127+
"Invalid professional registration number format. Accepted formats are: 1–2 letters followed by 6 digits (e.g., AB123456)" +
128+
" 4–8 digits only " + "Optional ‘P’ followed by 5–6 digits ‘C’ or ‘P’ followed by 6 digits " +
129+
"Optional letter followed by 5–6 digits ‘L’ followed by 4–6 digits 2 digits, hyphen, then 4–5 alphanumeric characters"
130+
122131
)]
123132
public void ValidateProfessionalRegistrationNumber_sets_error_when_prn_is_invalid(
124133
string prn,

DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public static void ValidateProfessionalRegistrationNumber(
4444
return;
4545
}
4646

47-
if (prn.Length < 4 || prn.Length > 20)
47+
if (prn.Length < 5 || prn.Length > 20)
4848
{
4949
modelState.AddModelError(
5050
"ProfessionalRegistrationNumber",
51-
"Professional registration number must be between 4 and 20 characters"
51+
"Professional registration number must be between 5 and 20 characters"
5252
);
5353
}
5454

0 commit comments

Comments
 (0)