40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
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
|
|
{
|
|
[Display(Prompt ="NOM COMPLET")]
|
|
public string Name { get; set; }
|
|
[Display(Prompt = "COURRIEL")]
|
|
public string Email { get; set; }
|
|
[Display(Prompt = "TÉLÉPHONE")]
|
|
public string Phone { get; set; }
|
|
[Display(Prompt = "VOS COMMENTAIRES")]
|
|
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("Une adresse courriel est requise")
|
|
.EmailAddress().WithMessage("Format non valide!");
|
|
|
|
RuleFor(x => x.Phone)
|
|
.NotEmpty().WithMessage("Vous devez entrer votre téléphone")
|
|
.Matches("^\\s*(?:\\+?(\\d{1}))?[-. (]*(\\d{3})[-. )]*(\\d{3})[-. ]*(\\d{4})$").WithMessage("Téléphone non valide!");
|
|
}
|
|
}
|
|
}
|