Joh*_*ohn 14 c# validation asp.net-mvc
使用RegularExpression(@"^\d{1,15}$")],我希望用户输入长度最多为15的数字,如果这不正确,则返回错误消息"请输入最多15位数的联系人号码"
[Required(ErrorMessage = ("Please enter up to 15 digits for a contact number")), Display(Name = "Contact Number"), RegularExpression(@"^\d{1,15}$")]
public string ContactNumber { get; set; }
如果用户没有这样做,我留下了错误消息:
The field Contact Number must match the regular expression '^\d{1,15}$'.
而不是'Please enter up to 15 digits for a contact number'......有谁知道为什么?谢谢
Dar*_*rov 35
您已将(由于正则表达式)分配ErrorMessage给RequiredAttribute(在这种情况下您绝对不需要).所以:
[Display(Name = "Contact Number")]
[RegularExpression(@"^\d{1,15}$", ErrorMessage = "Please enter up to 15 digits for a contact number")]
public string ContactNumber { get; set; }
| 归档时间: | 
 | 
| 查看次数: | 24685 次 | 
| 最近记录: |