Backend login and register
This commit is contained in:
29
src/Application/Validators/RegisterRequestValidator.cs
Normal file
29
src/Application/Validators/RegisterRequestValidator.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Application.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Application.Validators;
|
||||
|
||||
public class RegisterRequestValidator : AbstractValidator<RegisterRequest>
|
||||
{
|
||||
public RegisterRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.Email)
|
||||
.NotEmpty().WithMessage("{PropertyName} is required.")
|
||||
.EmailAddress().WithMessage("{PropertyName} is not valid.");
|
||||
|
||||
RuleFor(x => x.Password)
|
||||
.NotEmpty().WithMessage("{PropertyName} is required.")
|
||||
.MinimumLength(10).WithMessage("{PropertyName} must be at least 10 characters long.")
|
||||
.Matches("[A-Z]").WithMessage("{PropertyName} must contain at least one uppercase letter.")
|
||||
.Matches("[a-z]").WithMessage("{PropertyName} must contain at least one lowercase letter.")
|
||||
.Matches("[0-9]").WithMessage("{PropertyName} must contain at least one digit.")
|
||||
.Matches("[^a-zA-Z0-9]").WithMessage("{PropertyName} must contain at least one special character.");
|
||||
|
||||
RuleFor(x => x.Username)
|
||||
.NotEmpty().WithMessage("{PropertyName} is required.")
|
||||
.MinimumLength(3).WithMessage("{PropertyName} must be at least 3 characters long.")
|
||||
.MaximumLength(20).WithMessage("{PropertyName} must not exceed 20 characters.")
|
||||
.Matches("^[a-zA-Z0-9_]*$")
|
||||
.WithMessage("{PropertyName} can only contain letters, numbers, and underscores.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user