Skip to content

Commit f13f2e9

Browse files
TD-4624 Refactor the error message
1 parent 24d4146 commit f13f2e9

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ 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)]
112110
[TestCase("01234_", ErrorMessagesTestHelper.InvalidFormatError)]
113111
[TestCase("01234 ", ErrorMessagesTestHelper.InvalidFormatError)]
114112
[TestCase("01234$", ErrorMessagesTestHelper.InvalidFormatError)]

DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ namespace DigitalLearningSolutions.Web.Tests.TestHelpers
44
public static class ErrorMessagesTestHelper
55
{
66
public const string InvalidFormatError =
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).";
7+
@"The format you entered isn’t recognised. Please check and try again.
8+
Valid formats include
9+
7 digits - example, 1234567
10+
1-2 letters followed by 6 digits - example, AB123456
11+
‘P’ followed by 5-6 digits - example, P12345, P123456
12+
‘C’ or ‘P’ followed by 6 digits - example, C123456, P123456
13+
Optional letter followed by 5-6 digits - example, A12345, B123456
14+
‘L’ followed by 4-6 digits - example, L1234, L123456
15+
2 digits, hyphen, then 4-5 alphanumeric characters - example, 12-AB123";
1216

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

1620
}
1721
}

DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
namespace DigitalLearningSolutions.Web.Helpers
22
{
3+
using DocumentFormat.OpenXml.Spreadsheet;
34
using Microsoft.AspNetCore.Mvc.ModelBinding;
5+
using MimeKit;
6+
using System;
47
using System.Text.RegularExpressions;
58

69
public class ProfessionalRegistrationNumberHelper
@@ -39,28 +42,27 @@ public static void ValidateProfessionalRegistrationNumber(
3942
modelState.AddModelError("ProfessionalRegistrationNumber", "Enter a professional registration number");
4043
return;
4144
}
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})$";
45+
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})$";
5246
var rg = new Regex(pattern, RegexOptions.IgnoreCase);
5347
if (!rg.Match(prn).Success)
5448
{
5549
modelState.AddModelError(
5650
"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)."
51+
GetProfessionalRegistrationNumberErrorMessage()
6252
);
6353
}
6454
}
55+
public static string GetProfessionalRegistrationNumberErrorMessage()
56+
{
57+
return @"The format you entered isn’t recognised. Please check and try again.
58+
Valid formats include
59+
7 digits - example, 1234567
60+
1-2 letters followed by 6 digits - example, AB123456
61+
‘P’ followed by 5-6 digits - example, P12345, P123456
62+
‘C’ or ‘P’ followed by 6 digits - example, C123456, P123456
63+
Optional letter followed by 5-6 digits - example, A12345, B123456
64+
‘L’ followed by 4-6 digits - example, L1234, L123456
65+
2 digits, hyphen, then 4-5 alphanumeric characters - example, 12-AB123";
66+
}
6567
}
6668
}

0 commit comments

Comments
 (0)