Skip to content

Need a better solution for decimal range validation #43749

Closed
@h82258652

Description

@h82258652

Background and Motivation

Hello, I'm an asp.net core developer. While I using the input validation, I found it is hard to validate the decimal type.
I try these:

[Range(typeof(decimal), "0", decimal.MaxValue.ToString())]

This one compile error.

[Range(0d, (double)decimal.MaxValue)]

Works but it will lost the precision.

After I search google and stackoverflow, I found the solution:

[Range(typeof(decimal), "0", "79228162514264337593543950335")]

It is not friendly for code.
Also as @Joe4evr said, decimal type can not be an attribute parameter due to the CLR restriction.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions