|
1 | 1 | namespace DigitalLearningSolutions.Web.Helpers |
2 | 2 | { |
| 3 | + using DocumentFormat.OpenXml.Spreadsheet; |
3 | 4 | using Microsoft.AspNetCore.Mvc.ModelBinding; |
| 5 | + using MimeKit; |
| 6 | + using System; |
4 | 7 | using System.Text.RegularExpressions; |
5 | 8 |
|
6 | 9 | public class ProfessionalRegistrationNumberHelper |
@@ -39,28 +42,27 @@ public static void ValidateProfessionalRegistrationNumber( |
39 | 42 | modelState.AddModelError("ProfessionalRegistrationNumber", "Enter a professional registration number"); |
40 | 43 | return; |
41 | 44 | } |
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})$"; |
52 | 46 | var rg = new Regex(pattern, RegexOptions.IgnoreCase); |
53 | 47 | if (!rg.Match(prn).Success) |
54 | 48 | { |
55 | 49 | modelState.AddModelError( |
56 | 50 | "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() |
62 | 52 | ); |
63 | 53 | } |
64 | 54 | } |
| 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 | + } |
65 | 67 | } |
66 | 68 | } |
0 commit comments