Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 769063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:16:39+00:00 2026-05-14T18:16:39+00:00

I have a textbox and a datepicker next to it and I am using

  • 0

I have a textbox and a datepicker next to it and I am using asp.net and the user can enter the date as well select the date from datepicker.

How would you validate if the date is entered correct?

  <script type="text/javascript"> 
        $(document).ready(function () { 
            $('#<%=StartDate.ClientID%>').datepicker({ showOn: 'button', 
                    buttonImage: '../images/Calendar.png', 
                    buttonImageOnly: true, onSelect: function () { }, 
                    onClose: function () { $(this).focus(); } 
            }); 
        }); 
    </script> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:16:40+00:00Added an answer on May 14, 2026 at 6:16 pm

    If you’re using ASP.NET, you can use an ASP.NET Compare Validator [ASP.NET Date Validator].

    <asp:TextBox ID="tb" runat="server"></asp:TextBox>
    
    <asp:CompareValidator ID="cv" runat="server" 
    ControlToValidate="tb" ErrorMessage="* Please enter a valid date!" Text="*" 
    Operator="DataTypeCheck" Type="Date"></asp:CompareValidator>
    

    **** Update**

    I took the javascript that was executed by the Compare Validator above and wrapped a custom jQuery Validation method around it:

    <script type="text/javascript">
        $(document).ready(function () {
    
            $.validator.addMethod("truedate", function (value, element, params) {
                function GetFullYear(year, params) {
                    var twoDigitCutoffYear = params.cutoffyear % 100;
                    var cutoffYearCentury = params.cutoffyear - twoDigitCutoffYear;
                    return ((year > twoDigitCutoffYear) ? (cutoffYearCentury - 100 + year) : (cutoffYearCentury + year));
                }
    
                var yearFirstExp = new RegExp("^\\s*((\\d{4})|(\\d{2}))([-/]|\\. ?)(\\d{1,2})\\4(\\d{1,2})\\.?\\s*$");
                try {
                    m = value.match(yearFirstExp);
                    var day, month, year;
                    if (m != null && (m[2].length == 4 || params.dateorder == "ymd")) {
                        day = m[6];
                        month = m[5];
                        year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
                    }
                    else {
                        if (params.dateorder == "ymd") {
                            return null;
                        }
                        var yearLastExp = new RegExp("^\\s*(\\d{1,2})([-/]|\\. ?)(\\d{1,2})(?:\\s|\\2)((\\d{4})|(\\d{2}))(?:\\s\u0433\\.)?\\s*$");
                        m = value.match(yearLastExp);
                        if (m == null) {
                            return null;
                        }
                        if (params.dateorder == "mdy") {
                            day = m[3];
                            month = m[1];
                        }
                        else {
                            day = m[1];
                            month = m[3];
                        }
                        year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));
                    }
                    month -= 1;
                    var date = new Date(year, month, day);
                    if (year < 100) {
                        date.setFullYear(year);
                    }
                    return (typeof (date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? date.valueOf() : null;
                }
                catch (err) {
                    return null;
                }
            }, "Please enter an actual date.");
    
            $("#form1").validate();
    
            $("#one").rules('add',
            {
                truedate: {
                    cutoffyear: '2029',
                    dateorder: 'mdy'
                }
            });
        });
    
    </script>
    
    <input id="one" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the JQuery DatePicker to have the user pick a date and have
I have been using asp.net programming just from few months and I have to
I have 2 textbox in my asp.net page and also have one hiddenfield in
I have three TextBox controls on the page <asp:TextBox ID=TextBox1 runat=server AutoPostBack=True OnTextChanged=TextBox_TextChanged TabIndex=1>
I have a textbox and a link button. When I write some text, select
I have 2 textboxes: StartDate and endDate How can I make so the user
What's the object type returned by Datepicker? Supposing I have the following: $(#txtbox).datepicker({ onClose:
In my application I have TextBox in a FormView bound to a LinqDataSource like
I have a textbox whose input is being handled by jQuery. $('input.Search').bind(keyup, updateSearchTextbox); When
I have a textbox with the Text property bound to a dataset column with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.