Model验证简单易懂
public bool UserSex { get; set; }
//定义名字
[Display(Name = "年龄")]
[Range(0, 150, ErrorMessage = "年龄范围0-150")]
public int UserAge { get; set; }
[Required(ErrorMessage = "邮箱不能为空")]
[EmailAddress(ErrorMessage = "邮箱格式不正确")]
//[RegularExpression("^\\w@\\w.\\w$")]
public string UserEmail { get; set; }
[Required(ErrorMessage = "电话不能为空")]
//正则验证
[RegularExpression("^1[34578]\\d{9}$", ErrorMessage = "手机格式不正确")]
public string UserPhone { get; set; }
public string UserAddressName { get; set; }
public string UserHobby { get; set; }
[Required(ErrorMessage = "密码不能为空")]
public string UserPass { get; set; }
//密码验证
[Compare("UserPass", ErrorMessage = "两次密码输入不一致")]
public string ConfirmUserPass { get; set; }
public int AddressID { get; set; }