Best Data annotation for a Decimal(18,2)

后端 未结 8 1308
無奈伤痛
無奈伤痛 2020-12-14 05:57

I have a column inside my sql server 2008 wih type of Decimal(18,2). But on entity framework what is the best data annotation validation I can apply to this pro

8条回答
  •  长情又很酷
    2020-12-14 06:46

    This seems to be the correct answer ( the above answers either restrict valid numbers that can be inserted into a data type of Decimal(18,2) or cause compile errors if you apply them to your code -- please confirm for yourself):

    Use the following two constraints together:

    Two Decimal Points

    [RegularExpression(@"^\d+.?\d{0,2}$", ErrorMessage = "Invalid Target Price; Maximum Two Decimal Points.")]
    

    Max 18 digits

      [Range(0, 9999999999999999.99, ErrorMessage = "Invalid Target Price; Max 18 digits")]
    

提交回复
热议问题