我有一个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" }))
答案 0 :(得分:1)
在您的媒体资源上使用RegularExpressionAttribute
和RequiredAttribute
。
[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)
请注意,您应该删除required
,validationmessage
和data_required_msg
属性。
现在,这将为您提供客户端和(更重要的)服务器端验证。