Check length of integer value by annotation

Binumon George 161 Reputation points
2023-03-03T11:47:43.36+00:00

Hi All,

    In my  model i have integer property.  I want to check length of that property. 

public class test{

public int abc { get; set; }

}

test t=new test()

t.abc=123456789 // Here i want to make sure that length of value is 10 and its integer value

I am using this model for API. In API can accept list of data from user in a single call.

Public class ListofTest{

public<List> test t

}

My question is possible to check length of int data type using annotation?

I am using .net core 6 for developing API

Developer technologies ASP.NET ASP.NET Core
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 30,126 Reputation points
    2023-03-03T12:41:17.6166667+00:00

    The Range attribute validates the magnitude of a numeric type.

        public class Test
        {
            [Range(1000000000, int.MaxValue)]
            public int abc { get; set; }
        }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.