Skip to content

Commit 304cb3d

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

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void ValidateProfessionalRegistrationNumber_does_not_set_errors_when_vali
7070
{
7171
// Given
7272
var state = new ModelStateDictionary();
73-
const string validPrn = "abc-123";
73+
const string validPrn = "AB123456";
7474

7575
// When
7676
ProfessionalRegistrationNumberHelper.ValidateProfessionalRegistrationNumber(

DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
namespace DigitalLearningSolutions.Web.Helpers
22
{
3-
using System.Text.RegularExpressions;
3+
using DocumentFormat.OpenXml.ExtendedProperties;
4+
using DocumentFormat.OpenXml.Spreadsheet;
45
using Microsoft.AspNetCore.Mvc.ModelBinding;
6+
using Microsoft.CodeAnalysis;
7+
using System.Diagnostics.Metrics;
8+
using System.Text.RegularExpressions;
59

610
public class ProfessionalRegistrationNumberHelper
711
{
@@ -40,11 +44,11 @@ public static void ValidateProfessionalRegistrationNumber(
4044
return;
4145
}
4246

43-
if (prn.Length < 5 || prn.Length > 20)
47+
if (prn.Length < 4 || prn.Length > 20)
4448
{
4549
modelState.AddModelError(
4650
"ProfessionalRegistrationNumber",
47-
"Professional registration number must be between 5 and 20 characters"
51+
"Professional registration number must be between 4 and 20 characters"
4852
);
4953
}
5054

@@ -54,7 +58,9 @@ public static void ValidateProfessionalRegistrationNumber(
5458
{
5559
modelState.AddModelError(
5660
"ProfessionalRegistrationNumber",
57-
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
61+
"Invalid professional registration number format. Accepted formats are: 1–2 letters followed by 6 digits (e.g., AB123456)"+
62+
" 4–8 digits only "+"Optional ‘P’ followed by 5–6 digits ‘C’ or ‘P’ followed by 6 digits "+
63+
"Optional letter followed by 5–6 digits ‘L’ followed by 4–6 digits 2 digits, hyphen, then 4–5 alphanumeric characters"
5864
);
5965
}
6066
}

0 commit comments

Comments
 (0)