Reputation: 55
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
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