验证Kendo数字文本框以接受最多15位数分钟1

时间:2016-04-29 06:22:22

标签: asp.net-mvc model-view-controller kendo-ui

我有一个kendo文本框,我想验证手机号码

  @(Html.Kendo().TextBox().Name("MobileNo")
        .HtmlAttributes(new { @class = "form-control", style = "width:100%;", placeholder = "Enter Mobile Number  ", required = "required",validationmessage = "Enter {0}", data_required_msg = "Enter Mobile Number" }))

1 个答案:

答案 0 :(得分:1)

在您的媒体资源上使用RegularExpressionAttributeRequiredAttribute

[Required(ErrorMessage = "Please enter a mobile phone")]
[RegularExpression(@"^\d{1,15}$", ErrorMessage = "Please enter between 1 and 15 numbers")]
public string MobileNo { get; set; }

并在视图中

@(Html.Kendo().TextBox().Name("MobileNo")
    .HtmlAttributes(new { @class = "form-control", style = "width:100%;", placeholder = "Enter Mobile Number" }))
@Html.ValidationMessageFor(m => m.MobileNo)

请注意,您应该删除requiredvalidationmessagedata_required_msg属性。

现在,这将为您提供客户端和(更重要的)服务器端验证。