5

For example I have 2 items: Item1 is string and Item2 is int. How can I set max length for Item1 8 chars and for Item2 5 digits(in c#)?

Ria
  • 10,237
  • 3
  • 33
  • 60
Ali Ahmadi
  • 2,387
  • 4
  • 31
  • 48

1 Answers1

0

To do that, simply use StringLengthAttribute and IntegerValidatorAttribute.

class TestCase
{
  [StringLength(8, ErrorMessage = "The TestString value cannot exceed 8 characters.")]
  [Required(ErrorMessage="Value Required")]
  property string TestString;

  [IntegerValidator(MaxValue = 99999)]
  property int TestInt;
}
virious
  • 571
  • 1
  • 8
  • 27