MVC3 View验证
MVC3 View视图的几种常用验证
/// <summary> /// 热值 /// </summary> [Display(Name = "热值")] [Required(ErrorMessage = "必填")] //指定数据字段值的数值范围约束 [Range(0, 9999, ErrorMessage = "格式有误")] public decimal? HEATVALUE
//日期、时间、货币、Url的验证,此为货币验证 [DataType(System.ComponentModel.DataAnnotations.DataType.Currency,ErrorMessage="格式错误")] //指定ASP.NET 动态数据中的数据字段值必须与指定的正则表达式匹配 [RegularExpression(@"^\d{0,6}(\.\d{0,2})?$", ErrorMessage = "格式有误")] //指定数据字段中允许的最小和最大字符长度 [StringLength(50, ErrorMessage = "字符长度有误")] /// <summary> /// 确认密码 /// </summary> [Display(Name = "确认密码")] [Required(ErrorMessage="必填")] [DataType(System.ComponentModel.DataAnnotations.DataType.Password)] [StringLength(20, ErrorMessage = "长度不能超过20个字符")] [Compare("PASSWORD", ErrorMessage = "确认密码与登录密码不一致")] public string REPASSWORD { get { return _REPASSWORD; } set { _REPASSWORD = value; } }
[Display(Name = "手机号码")] [Required(ErrorMessage="必填")] [StringLength(25, ErrorMessage = "长度不能超过25个字")] [RegularExpression(ValidationExpressionString.Mobile, ErrorMessage = "格式有误")] [Display(Name = "电子邮箱")] [StringLength(30, ErrorMessage = "长度不能超过30个字")] [RegularExpression(ValidationExpressionString.Email, ErrorMessage = "格式有误")] [Display(Name = "传真")] [StringLength(25, ErrorMessage = "长度不能超过25个字")] [RegularExpression(ValidationExpressionString.Fax,ErrorMessage="格式有误")]
{ get { return _HEATVALUE; } set { _HEATVALUE = value; } }