Custom Validation Attribute

CustomValidation.cs (Model/Dto)

public class CustomValidation
{
    [Required(ErrorMessage = "Vui lòng nhập Id")]
    public int? Id { get; set; }

    [Required(ErrorMessage = "Vui lòng nhập tên")]
    public string Name { get; set; }
    
    [Required(ErrorMessage = "Vui lòng nhập email")]
    [RegularExpression(@"^[\w-\.]+@([\w-]+\.)+[\w-]*", ErrorMessage = "Email không đúng định dạng")]
    public string Email { get; set; }
    
    [MinLength(9, ErrorMessage = "Số điện thoại không hợp lệ")]
    [MaxLength(15, ErrorMessage = "Số điện thoại không hợp lệ")]
    [Required(ErrorMessage = "Vui lòng nhập số điện thoại")]
    public string PhoneNumber { get; set; }
}

CustomAttribute.cs

Last updated

Was this helpful?