I have one Textbox. I want to restrict that textbox to allow only years[4 digit].
year must be ranges from 1940 to current year
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Shankar MRank #874 · 2.5K reputationPosted Dec 12, 2013, 8:31 PM EST
You can set the TextBox MaxLength property to 4 which restrict itself to enter 4 characters only.
Thanks,
Shankar
samantaRank #3,157 · 454 reputationPosted Dec 12, 2013, 8:34 PM EST
But i want to enter only year in that and it must accept year from 1940 to current year
Shankar MRank #874 · 2.5K reputationPosted Dec 12, 2013, 8:43 PM EST
Then, you can use the Server Control Range Validator. Here it is.
You can use the ControlToValidate property to set the TextBox that need to be validated,
and by specifying the Min and Max value.
<asp:RangeValidator ID ="RangeValidator1" runat ="server" ControlToValidate ="txtFiche" MinimumValue ="1940" MaximumValue = "2013" ErrorMessage ="Invalid Input">
asp:RangeValidator>Thanks,
Shankar M
samantaRank #3,157 · 454 reputationPosted Dec 12, 2013, 9:19 PM EST
But if year changes from 2013 to 2014 than?
i dont want to change again.
Shankar MRank #874 · 2.5K reputationPosted Dec 12, 2013, 9:27 PM EST