Ajout du formulaire

This commit is contained in:
Jean-Daniel Lamontagne
2022-09-12 17:14:11 -04:00
parent fbbb3bf83c
commit 166db82ed3
5 changed files with 109 additions and 15 deletions

View File

@@ -0,0 +1,35 @@
using FluentValidation;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace GrossesMitaines.Models
{
public class RequestViewModel
{
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Message { get; set; }
}
public class RequestValidator : AbstractValidator<RequestViewModel>
{
public RequestValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Vous devez entrer votre nom")
.MinimumLength(2).WithMessage("Votre nom doit être de 2 lettres minimum");
RuleFor(x => x.Email)
.NotEmpty().WithMessage("Un Email est requis")
.Matches("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$").WithMessage("Format non valide!");
RuleFor(x => x.Phone)
.NotEmpty().WithMessage("Vous devez entrer votre téléphone")
.Matches("^[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$").WithMessage("Téléphone non valide!");
}
}
}