Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Text box validation issue

I am a beginner of .NET coding.

How can we give validation for a text box in which only positive integers are allowed?

like image 632
naren Avatar asked Nov 30 '25 23:11

naren


1 Answers

Use the Range attribute on your Model property:

[Range(0, int.MaxValue)]
public int YourNumber { get; set; }
like image 185
mattytommo Avatar answered Dec 02 '25 15:12

mattytommo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!