Skip to content

Commit b2e07f9

Browse files
authored
Merge pull request #2103 from TechnologyEnhancedLearning/Develop/Fixes/TD-2285_Areas_missing_validations_on_the_fields_across_the_DLS_application
TD-2285 Added validations in "Edit centre details","Edit centre manager","Edit details","Edit user details" and "Edit delegate details" pages
2 parents 4c83b67 + 7846e42 commit b2e07f9

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

DigitalLearningSolutions.Web/Helpers/PromptsService.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6+
using System.Text.RegularExpressions;
67
using DigitalLearningSolutions.Data.Models.CustomPrompts;
78
using DigitalLearningSolutions.Data.Models.User;
89
using DigitalLearningSolutions.Data.Utilities;
@@ -247,6 +248,15 @@ ModelStateDictionary modelState
247248
var errorMessage = $"{delegateRegistrationPrompt.Prompt} must be at most 100 characters";
248249
modelState.AddModelError("Answer" + delegateRegistrationPrompt.PromptNumber, errorMessage);
249250
}
251+
if (delegateRegistrationPrompt.Prompt?.ToLower().Contains("telephone") ?? false)
252+
{
253+
Regex regex = new Regex(@"^\w{4}\d{6,7}$");
254+
if (!string.IsNullOrEmpty(delegateRegistrationPrompt.Answer) && !regex.IsMatch(delegateRegistrationPrompt.Answer))
255+
{
256+
var errorMessage = $"{delegateRegistrationPrompt.Prompt} must be in correct format";
257+
modelState.AddModelError("Answer" + delegateRegistrationPrompt.PromptNumber, errorMessage);
258+
}
259+
}
250260
}
251261
}
252262

DigitalLearningSolutions.Web/ViewModels/SuperAdmin/Centres/EditCentreDetailsSuperAdminViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public EditCentreDetailsSuperAdminViewModel(Centre centre)
3232
[EmailAddress(ErrorMessage = "Enter an email in the correct format, like [email protected]")]
3333
[NoWhitespace(ErrorMessage = "Email must not contain any whitespace characters")]
3434
public string? CentreEmail { get; set; }
35+
36+
[RegularExpression(@"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}", ErrorMessage = "Enter an Ip in the correct format.")]
3537
public string? IpPrefix { get; set; }
3638
public bool ShowOnMap { get; set; }
3739
}

DigitalLearningSolutions.Web/ViewModels/SuperAdmin/Users/EditUserDetailsViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ public EditUserDetailsViewModel(UserAccount userAccount)
2323
public int Id { get; set; }
2424

2525
[Required(ErrorMessage = "Enter a first name")]
26+
[MaxLength(250, ErrorMessage = CommonValidationErrorMessages.TooLongFirstName)]
2627
public string FirstName { get; set; }
2728

2829
[Required(ErrorMessage = "Enter a last name")]
30+
[MaxLength(250, ErrorMessage = CommonValidationErrorMessages.TooLongLastName)]
2931
public string LastName { get; set; }
3032

3133
public int JobGroupId { get; set; }

DigitalLearningSolutions.Web/ViewModels/TrackingSystem/Centre/Configuration/EditCentreManagerDetailsViewModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Centre.Configur
33
using System.ComponentModel.DataAnnotations;
44
using DigitalLearningSolutions.Data.Models.Centres;
55
using DigitalLearningSolutions.Web.Attributes;
6+
using DigitalLearningSolutions.Web.Helpers;
67

78
public class EditCentreManagerDetailsViewModel
89
{
@@ -20,11 +21,11 @@ public EditCentreManagerDetailsViewModel(Centre centre)
2021
public int CentreId { get; set; }
2122

2223
[Required(ErrorMessage = "Enter a first name")]
23-
[MaxLength(250, ErrorMessage = "First name must be 250 characters or fewer")]
24+
[MaxLength(250, ErrorMessage = CommonValidationErrorMessages.TooLongFirstName)]
2425
public string? FirstName { get; set; }
2526

2627
[Required(ErrorMessage = "Enter a last name")]
27-
[MaxLength(250, ErrorMessage = "Last name must be 250 characters or fewer")]
28+
[MaxLength(250, ErrorMessage = CommonValidationErrorMessages.TooLongLastName)]
2829
public string? LastName { get; set; }
2930

3031
[Required(ErrorMessage = "Enter an email")]
@@ -34,6 +35,7 @@ public EditCentreManagerDetailsViewModel(Centre centre)
3435
public string? Email { get; set; }
3536

3637
[MaxLength(250, ErrorMessage = "Telephone number must be 250 characters or fewer")]
38+
[RegularExpression(@"[0-9 ]+", ErrorMessage = "Enter a Telephone number in the correct format.")]
3739
public string? Telephone { get; set; }
3840
}
3941
}

0 commit comments

Comments
 (0)