I have a form with a text box that should only accept 4 digit year values between 1980-2011. I'm sure there should be a simple c# validation control to implement this validation check, but I can't seem to find it.
Any suggestions?
Catch Validating event and add you validation code in there.
For a complete example check MSDN page.
For simple validation you can also use a MaskedTextBox.
First I'd say, use the max length property set to 4 so that no extra characters can be entered
Beyond that you would have to hook up your own controls to validate it (could be a on text changed validation, on lost focus, etc) that would check that only digits are entered and they are between your specified values
A MaskedTextBox would do the trick. Set the mask to your needs: msdn. But I doubt it will check if the value is between a range. It probably only checks if the value is a integer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With