Phone Number Validation MVC

后端 未结 9 1316
轮回少年
轮回少年 2020-12-07 20:51

I am trying to use a regular expression to validate a phone number and return an error when an invalid number or phone number is submitted.

MVC Code

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 21:30

    Along with the above answers Try this for min and max length:

    In Model

    [StringLength(13, MinimumLength=10)]
    public string MobileNo { get; set; }
    

    In view

     
    @Html.TextBoxFor(m => m.MobileNo, new { @class = "form-control" , type="phone"}) @Html.ValidationMessageFor(m => m.MobileNo,"Invalid Number") @Html.CheckBoxFor(m => m.IsAgreeTerms, new {@checked="checked",style="display:none" })

提交回复
热议问题