The DataAnnotations [Phone] Attribute

前端 未结 2 1171
南方客
南方客 2021-02-07 05:10

What is the default, valid format of the [Phone] attribute? In the data table, the phone column is navrchar (16) If I enter a phone # like 1112223333, I get \"field is not a va

2条回答
  •  误落风尘
    2021-02-07 05:19

    Try this -

      [Required(ErrorMessage = "Mobile no. is required")]
      [RegularExpression("^(?!0+$)(\\+\\d{1,3}[- ]?)?(?!0+$)\\d{10,15}$", ErrorMessage = "Please enter valid phone no.")]
      public string Phone { get; set; }
    

提交回复
热议问题