Mvc validation regular expression only numbers?

后端 未结 3 1883
梦如初夏
梦如初夏 2021-02-14 09:45

I tried the following code for digits-only validation for a contact number validation in Mvc web app.

[RegularExpression(@\"/(^\\(\\d{10})?)$/\", ErrorMessage =          


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-02-14 10:15

    If don't have any restrictions other than numbers only, this should fit:

    [RegularExpression(@"^\d+$", ErrorMessage = "Please enter proper contact details.")]
    [Required]
    [Display(Name = "Contact No")]
    public string ContactNo { get; set; }
    

提交回复
热议问题