diff --git a/src/Application/Common/Validators/RegularExpressionValidation.cs b/src/Application/Common/Validators/RegularExpressionValidation.cs index ed421450..4a636720 100644 --- a/src/Application/Common/Validators/RegularExpressionValidation.cs +++ b/src/Application/Common/Validators/RegularExpressionValidation.cs @@ -5,6 +5,12 @@ public static class ValidationConstants public const string LettersSpacesUnderscores = @"^[A-Za-z_ ]+$"; public const string LettersSpacesUnderscoresMessage = "{0} must contain only letters, spaces, and underscores."; + public const string LettersSpacesCommaApostorphe = @"^[A-Za-z ',’]+$"; + public const string LettersSpacesCommaApostropheMessage = "{0} must contain only letters, spaces, comma and an apostrophe."; + + public const string AlphabetsDigitsSpaceSlashHyphenDot= @"^[a-zA-Z0-9\s\\\/\-.]+$"; + public const string AlphabetsDigitsSpaceSlashHyphenDotMessage = "{0} must contain only alphabet (both uppercase and lowercase), digit, space, backslash, forward slash, hyphen, and dot."; + public const string DateMustBeInPast = "Date must be in the past."; public const string DateMustBeInFuture = "Date must be in the future."; @@ -13,6 +19,9 @@ public static class ValidationConstants public const string GuidMessage = "{0} must contain a valid Guid"; + public const string Numbers = @"^[0-9]*$"; + public const string NumbersMessage = "{0} must contain only numbers"; + public const string AlphaNumeric = @"^[a-zA-Z0-9]*$"; public const string AlphaNumericMessage = "{0} must contain only alphanumeric characters"; @@ -30,8 +39,8 @@ public static class ValidationConstants public const int MaximumPageSize = 50; public const string MaximumPageSizeMessage = "Page size must be between 1 and 50."; - public const string TenantId = @"^[0-9]+(?:\\.[0-9]+)*\\.$"; - public const string TenantIdMessage = "Must start with a number and end with a period for example 1.2.1."; + public const string TenantId = @"^(\d+(\.\d+)*\.)$"; + public const string TenantIdMessage = "Invalid format for Tenant Id"; public const string TenantDomain = @"^@[a-z0-9]+(?:[-]?[a-z0-9]+)*(?:\.[a-z0-9]+(?:[-]?[a-z0-9]+)*)+$"; public const string TenantDomainMessage = "Must be in the format '@example.com'"; diff --git a/src/Application/Features/Identity/DTOs/ApplicationUserDtoValidator.cs b/src/Application/Features/Identity/DTOs/ApplicationUserDtoValidator.cs index 022155bb..f37c8bd1 100644 --- a/src/Application/Features/Identity/DTOs/ApplicationUserDtoValidator.cs +++ b/src/Application/Features/Identity/DTOs/ApplicationUserDtoValidator.cs @@ -18,15 +18,10 @@ public ApplicationUserDtoValidator( .NotEmpty().WithMessage(_localizer["Tenant name is required"]) .Matches(ValidationConstants.TenantId).WithMessage(_localizer[ValidationConstants.TenantIdMessage]); - RuleFor(x => x.ProviderId) - .MaximumLength(50).WithMessage(_localizer["Provider must be less than 50 characters"]) - .NotEmpty().WithMessage(_localizer["Provider is required"]) - .Matches(ValidationConstants.AlphaNumeric).WithMessage(_localizer[string.Format(ValidationConstants.AlphaNumericMessage, "Provider Id")]); - RuleFor(x => x.DisplayName) .MaximumLength(100).WithMessage(_localizer["Display Name is required and must be less than or equal to 100 characters"]) .NotEmpty().WithMessage(_localizer["Display Name is required"]) - .Matches(ValidationConstants.AlphaNumeric).WithMessage(_localizer[string.Format(ValidationConstants.AlphaNumericMessage, "Display Name")]); + .Matches(ValidationConstants.NameCompliantWithDMS).WithMessage(_localizer[string.Format(ValidationConstants.NameCompliantWithDMSMessage, "Display Name")]); RuleFor(x => x.Email) .NotEmpty().WithMessage(_localizer["E-mail is required"]) @@ -58,14 +53,16 @@ public ApplicationUserDtoValidator( RuleFor(x => x.PhoneNumber) .MaximumLength(20).WithMessage(_localizer["Mobile number must be less than or equal to 20 digits"]) - .Matches(ValidationConstants.AlphaNumeric).WithMessage(_localizer[string.Format(ValidationConstants.AlphaNumericMessage, "Mobile number")]); + .Matches(ValidationConstants.Numbers).WithMessage(_localizer[string.Format(ValidationConstants.NumbersMessage, "Mobile number")]); RuleFor(x => x.MemorablePlace) .MaximumLength(50).WithMessage(_localizer["Memorable place must be less than or equal to 50 characters"]) - .Matches(ValidationConstants.AlphaNumeric).WithMessage(_localizer[string.Format(ValidationConstants.AlphaNumericMessage, "Memorable place")]); + .Matches(ValidationConstants.LettersSpacesCommaApostorphe).WithMessage(_localizer[string.Format(ValidationConstants.LettersSpacesCommaApostropheMessage, "Memorable place")]); RuleFor(x => x.MemorableDate) - .NotEmpty().WithMessage(_localizer["Memorable date is required"]); + .NotEmpty().WithMessage(_localizer["Memorable date is required"]) + .MaximumLength(50).WithMessage(_localizer["Memorable place must be less than or equal to 50 characters"]) + .Matches(ValidationConstants.AlphabetsDigitsSpaceSlashHyphenDot).WithMessage(_localizer[string.Format(ValidationConstants.AlphabetsDigitsSpaceSlashHyphenDotMessage, "Memorable date")]); ; RuleForEach(x => x.Notes).ChildRules(notes => {