3

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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

But if I use regular expression I cant add a range check too?
Well, yes, but its not that easy. regular-expressions.info/numericranges.html
I believe the OP was asking how to get the custom error message to show up. '554g' appears to be a test value to test the error message. I have the same question of how to make it use my own custom error message and not the default one, which is how ended up here.
1

You have to add a regular expression in this case, like:

 [RegularExpression(@"^[1-1000]{1,4}$", ErrorMessage = "RangeAllowed")]
 public object ObjectLimit { get; set; }

This will catch if you provide non integer values.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.