Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
Good Afternoon all of you dear friends !!

Validation for Textbox
=======================

Validation for textbox if the year is less than current year.I need to enter further years not back years.
Message : Please enter valid year.


Please help me, an trying a lot .

Thank you
Posted
Comments
StianSandberg 16-Jul-12 5:56am    
this is 3. time you post the exact same question today...
http://www.codeproject.com/Questions/422082/Textbox-validation-for-year-2013
http://www.codeproject.com/Questions/422017/how-to-validate-textbox-with-previous-year
Mohamed Mitwalli 16-Jul-12 6:15am    
Did you try any of the answers in previous Question you post ?
Sandeep Mewara 16-Jul-12 8:24am    
Multiple reposts.

I have already explained in detail on how to achieve it.

C#
if(Convert.ToInt32(txtBox.Text)<Datetime.Today.Year)
{
//"Your message goes here"
}
 
Share this answer
 
v4
Hi,
try this javascript validation
JavaScript
//Javascript Function

function YearValidation() {
            var txtYear = document.getElementById('<%=txtYear.ClientID %>');
            if (parseInt(txtYear.value, 10) < parseInt(new Date().getFullYear())) {
                alert('Enter Valid year');
                txtYear.focus();
                return false;
            }
        }

Calling
XML
<asp:TextBox ID="txtYear" runat="server"></asp:TextBox>
      <asp:Button runat="server" Text="Button" OnClientClick="return YearValidation()"/>
 
Share this answer
 
Comments
Software Engineer 892 16-Jul-12 6:43am    
Many Thanks Nilesh patil its working now.
Nilesh Patil Kolhapur 16-Jul-12 6:49am    
welcome accept so other can get exact solution

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