PhoneNumber.cs 492 B

123456789101112131415161718192021
  1. using System.ComponentModel.DataAnnotations;
  2. using FluentValidation;
  3. namespace BlazorEditForms.Model;
  4. public class PhoneNumber
  5. {
  6. [Phone]
  7. public string Number { get; set; } = string.Empty;
  8. public PhoneNumberType Type { get; set; }
  9. }
  10. public class PhoneNumberValidator : AbstractValidator<PhoneNumber>
  11. {
  12. public PhoneNumberValidator()
  13. {
  14. RuleFor(x => x.Number).NotEmpty().Matches(@"\+?\d+");
  15. RuleFor(x => x.Type).IsInEnum();
  16. }
  17. }