1
0
mirror of https://github.com/XFox111/PhonebookService.git synced 2026-04-22 06:29:55 +03:00
Files
PhonebookService/PhonebookService.Domain/Validators/PhonebookRecordValidator.cs
T
2023-02-22 16:20:09 +03:00

25 lines
943 B
C#
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.ComponentModel.DataAnnotations;
using FluentValidation;
using PhonebookService.Domain.Models;
namespace PhonebookService.Domain.Validators;
/// <summary>
/// Validator class for <see cref="Models.PhonebookRecord"/>
/// </summary>
public class PhonebookRecordValidator : AbstractValidator<PhonebookRecord>
{
public PhonebookRecordValidator()
{
RuleFor(i => i.Email).EmailAddress();
RuleFor(i => i.PhoneNumber).Must(i => new PhoneAttribute().IsValid(i)); // The easiest way is to use .NET built-in validator
RuleFor(i => i.FirstName).NotEmpty();
RuleFor(i => i.LastName).NotEmpty();
RuleFor(i => i.StreetAddress).NotEmpty();
RuleFor(i => i.City).NotEmpty();
// Fun fact: the longest settlement name is "Llanfair­pwllgwyngyll­gogery­chwyrn­drobwll­llan­tysilio­gogo­goch" (66 characters)
// It is a village located in Wales, UK
RuleFor(i => i.ZipCode).Must(i => new ZipCodeValidator().IsValid(i));
}
}