Validate decimal value to 2 decimal places with data annotations?

前端 未结 8 1418
青春惊慌失措
青春惊慌失措 2020-12-03 07:20

I have this in my view model:

[Required(ErrorMessage = \"Price is required\")]
[Range(0.01, 999999999, ErrorMessage = \"Price must be greater than 0.00\")]
[         


        
8条回答
  •  执念已碎
    2020-12-03 08:00

    Similar to mattytommo. You need to escape '.' - otherwise ANY character will be accepted

    [RegularExpression(@"^\d+(\.\d{1,2})?$")]
    

提交回复
热议问题