You must Sign In to post a response.
  • Category: .NET

    Date validations in c#.net

    Iam having a date format [2005/03/03].i have to check date not exceeded 31 days and month
    having 12 month in c#.net
  • #762288
    Hi
    Narayan

    Normally Date Control not allow not exceed Date
    thats default but if you use only textbox we need to check for this

    you can use ajax control over come this issue try this code. we canot type wrongly this control this is automatically validate so use this code any issue means let me know.


    <AjaxToolkits:ToolkitScriptManager ID = "ToolkitScriptManager1" runat = "server"></AjaxToolkits:ToolkitScriptManager>


    <asp:TextBox ID="txtDate" runat="server" ReadOnly="true"></asp:TextBox>
    <asp:ImageButton ID="imgPopup" ImageUrl="images/calendar.png" ImageAlign="Bottom"
    runat="server" />
    <AjaxToolkits:CalendarExtender ID="Calendar1" PopupButtonID="imgPopup" runat="server" TargetControlID="txtDate"
    Format="dd/MM/yyyy">
    </AjaxToolkits:CalendarExtender>

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762290
    Hello V.Narayanaprasad,

    Refer the below code :

    using System.Globalization;

    private void btnCheck_Click(object sender, EventArgs e)
    {
    DateTime dt;
    if (DateTime.TryParseExact(textBox1.Text, "yyyy/MM/dd", null, DateTimeStyles.None, out dt) == true)
    {
    MessageBox.Show("Valid Date.");
    }
    else
    {
    MessageBox.Show("Invalid Date.");
    }
    }

    See attached image. It's an output i have got using above mentioned code.

    Hope this will help you.
    Choose As Best Answer if it helped you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #762296
    Hi Narayanaprasad,

    Usually for date picking we are using DatePicker control, in online we have several datepickers, in all controls date and month list will be same, it might be differ in format. Then why it is required to handle month and date validation, please elaborate your requirement. so, that we can help you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762297
    Hello Naveen,

    I think his questions needs an answer in Windows Application using C#.

    As i have seen his question points the category - .NET not ASP.NET

    So the answer needs for windows application.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762307
    Hi Nirav,

    That should be confirmed by creator of this post, I seen number of people, select different category but they are expecting in different language, this is happens some time. At-least they should be elaborate their requirement first then only we can decide what their requirement, whether our post is satisfied their requirement or not..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments