Junaid Zubair
Junaid Zubair

Reputation: 55

Why this range attribute in mvc does not give me right answer.?

I'm trying to apply range attribute on my class field like this.

 [Range(typeof(Int32), "1","999", ErrorMessage = "Must be a Number between 1  and 999")]

 public long? FieldName{ get; set; }

But it doesn't validate the range as I was expecting. It is supposed to validate range between 1 and 999. How to resolve this issue.

Upvotes: 0

Views: 326

Answers (1)

Jayaprakash
Jayaprakash

Reputation: 69

Try this..........

[Range(typeof(Int32), "1", "999", ErrorMessage = "Must be a positive natural Number between 1 and 999")] [RegularExpression("^[0-9]{1,3}$", ErrorMessage = "Must be a positive natural Number between 1 and 999")] public long? FieldName { get; set; }

Upvotes: 1

Related Questions