首页 > 代码库 > model验证(验证登录、注册...)

model验证(验证登录、注册...)

public class Student    {        public int ID { get; set; }        [Required(ErrorMessage = "学生姓名不能为空")]        [StringLength(4, ErrorMessage = "最多只能输入4个字符")]        public string Name { get; set; }        [Required(ErrorMessage = "性别不能为空")]        public int Sex { get; set; }        [Required(ErrorMessage = "年龄不能为空")]        [Range(10, 30, ErrorMessage = "年龄必须在10到30岁之间")]        public uint Age { get; set; }        [Required]        public string Telphone { get; set; }        public string stuNumber { get; set; }        [Required(ErrorMessage = "请输入账号")]        [Remote("CheckUserName", "Student", ErrorMessage = "该账号已注册")]        public string UserName { get; set; }        [Required(ErrorMessage = "请输入密码")]        //[RegularExpression(@"^.[*A-Za-z0-9\w_-]+.*$", ErrorMessage = "密码格式有误")]        public string Password { get; set; }        [Required(ErrorMessage = "请输入密码")]        [System.Web.Mvc.Compare("Password",ErrorMessage="密码不一致")]        public string RePassword { get; set; }    }

 

model验证(验证登录、注册...)