using System;
using System.ComponentModel.DataAnnotations;
namespace Webdiyer.MvcPagerDemo.Models
{
public class Users
{
public int ID { get; set; }
[DataType(DataType.PhoneNumber)]
public int MinPrice { get; set; }
[RegularExpression(@"^(0|[1-9][0-9]*)$", ErrorMessage = "MaxPrice的格式不正确")]
public int? MaxPrice { get; set; }
}
}
MinPrice 验证是正常的,输入英文字母等会报"The field MinPrice must be a number." MaxPrice 输入0开头的数字会报错,输入abcd和符号类却不会报错,这个正则表达式“^(0|[1-9][0-9]*)$”在别的网站试过了,输入非数字是会报NOT MATCH的,只有输入非0开头的正整数或0才会match。想请教下哪里出现问题了。
View 里面是这样写的
@Html.EditorFor(model => model.MaxPrice)
@Html.ValidationMessageFor(model => model.MaxPrice)