1.金额(10位整数,2位小数)
#region 余额 /// <summary> /// 余额 /// </summary> [DisplayName("余额")] [RegularExpression(@"^\d{1,10}(?:\.\d{1,2})?$", ErrorMessage = "金额输入有误!")] [DataType(DataType.Text)] [DisplayFormat(ConvertEmptyStringToNull = true)] public decimal Balances { get; set; } #endregion
2.整数验证
>=0
#region 标识 /// <summary> /// 标识 /// </summary> [DisplayName("标识")] [Required(ErrorMessage = "标识不得为空")] [DataType(DataType.Text)] [DisplayFormat(ConvertEmptyStringToNull = false)] [RegularExpression(@"^[0-9]*$", ErrorMessage = "标识不是整数")] [Remote("IsCodeValid", "Controller", "area", AdditionalFields = "ID", ErrorMessage = "标识不能重复!")] public int CodeID { get; set; } #endregion
>0
[RegularExpression(@"^\+?[1-9][0-9]*$", ErrorMessage = "不是正整数")]