Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ErrorMessage with Range using Data annotations

I have this:

    [Range(1, 1000, ErrorMessage = "Enter a value between 1 and 1000")]
    public object ObjectLimit { get; set; }

Works great, but it doesnt show the error message, it shows some standard "The value '554g' is not valid for the ObjectLimit field."

How do I fix that?

like image 983
Lasse Edsvik Avatar asked Mar 09 '26 00:03

Lasse Edsvik


1 Answers

Your setting a range of valid integers, 554g is not an integer.

Looks like you need a RegulagExpression attribute with the correct expression to match 554g as a correct value.

like image 64
John Farrell Avatar answered Mar 10 '26 13:03

John Farrell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!