Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Textbox validation
===================

How to Validate textbox to enter next year date.

it must NOT accept last year.. only it should accept forward years.


Please help.

Thank you
Posted
Comments
StianSandberg 16-Jul-12 3:45am    
you just asked the same question http://www.codeproject.com/Answers/422035/how-to-validate-textbox-with-previous-year
Software Engineer 892 16-Jul-12 3:47am    
ya, but it doesn't work........ please help me.
StianSandberg 16-Jul-12 3:53am    
are you using jquery unobtrusive validation? Or do you need a custom javascript validation? server side validation?
Sandeep Mewara 16-Jul-12 4:55am    
Whats the point of repost? Thats considered rude.

You can use CompareValidator for that. Follow the steps:

1. Drag and drop a CompareValidator from the toolbox to a suitable place you like.
2. Set the Operator to GreaterThan
3. Set the ControlToValidate property to the TextBox (which has the year)
4. Set the ValueToCompare on the Page Load Event to the current year

Do tell me if that helps. If not, please comment and I will modify the answer accordingly. Thanks.
 
Share this answer
 
Comments
Software Engineer 892 16-Jul-12 4:05am    
what to write on page load...Please help
Mohamed Mitwalli 16-Jul-12 4:08am    
you have to write nothing it's Client side validator
Pankaj Nikam 16-Jul-12 4:10am    
In the page load, you have to write something like:

CompareValidator1.ValueToCompare = DateTime.Now.Year;
Mohamed Mitwalli 16-Jul-12 4:09am    
5+
Pankaj Nikam 16-Jul-12 4:19am    
Thank you :)
Hi ,
Did you noticed that you post the same Question www.codeproject.com/Answers/422080/how-to-validate-textbox-with-previous-year[^]
Go and Check there it's already Answer
Best Regards
M.Mitwalli
 
Share this answer
 
Comments
Pankaj Nikam 16-Jul-12 4:21am    
I didnt knew that its a re-post... +5 to your answer too :)
Mohamed Mitwalli 16-Jul-12 4:27am    
Thanks Pankaj :)
Hi,

If your requirement is like that depending on System Date you only accept Next Year of current System Year.


In time of validation you will check Text Box value is Equals to
C#
System.DateTime.Today.Year+1
or not if not then throw some validation error

:)

If you try it on web then OnLoad put current Year value at hidden field On in Session On Cookie and Then On Submit check using Javascript by writing some javascript.

Do you need that java script
 
Share this answer
 
v2
Comments
Software Engineer 892 16-Jul-12 4:13am    
yes
Software Engineer 892 16-Jul-12 4:14am    
yes, i need javascript
Software Engineer 892 16-Jul-12 4:18am    
Boss, actually this is my registration form, i this am using check user availability also.

Please help.
Pankaj Nikam 16-Jul-12 4:22am    
If you follow my answer you will get both validations, Server side (code) and Client Side (JavaScript) too.
Software Engineer 892 16-Jul-12 4:18am    
May be , due to this it is not showing the year problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900