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

  • SEARCH
  • Home
  • 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 5962809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:09:28+00:00 2026-05-22T19:09:28+00:00

I am validating date using customvalidator but this is not working well can any

  • 0

I am validating date using customvalidator but this is not working well can any one tell why

This is my .aspx

    <script type="text/javascript">

function monthDiff(d1, d2) {
    var months;
    months = (d2.getFullYear() - d1.getFullYear()) * 12;
    months -= d1.getMonth() + 1;
    months += d2.getMonth();
    return months;
}

function difference(d1,d2){

var hiredate,dob;
var diff=18*12;
hiredate=document.getElementById(d1).value;
dob=document.getElementById(d2).value;
var months=monthDiff(hiredate,dob);
if(diff<=months)
{
return true;
//true
}
else
{
return false;
//false
}
}

function validatehiredate(value, arg) {
                arg.IsValid = (difference('ctl00_ContentPlaceHolder1_txtHiredate','ctl00_ContentPlaceHolder1_txtDateofBirth'));
            }
</script>

 <asp:TextBox id="txtHiredate" runat="server" />
 <asp:TextBox id="txtDateofBirth" runat="server" />
 <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="validatehiredate" ControlToValidate="txtDateofBirth" ValidationGroup="personal" Display="Dynamic" ValidateEmptyText="True">can not hire guy less than 18 yrs</asp:CustomValidator>

Can any one tell what’s wrong in this

  • 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-22T19:09:29+00:00Added an answer on May 22, 2026 at 7:09 pm

    change your monthDiff function to the below:

     function monthDiff(d1, d2) {
            var months;
            var date1 = new Date(d1);
            var date2 = new Date(d2);
    
            months = (date2.getFullYear() - date1.getFullYear()) * 12;
            months -= date1.getMonth() + 1;
            months += date2.getMonth(); return months;
           }
    

    you can’t use the getFullYear or getMonth on anything other than date objects.

    I am going to make the assumption that you’re browser is throwing a javascript error, it’s just not popping up

    EDIT

            function getDays(d1, d2) {
                var months;
                var date1 = new Date(d1);
                var date2 = new Date(d2);
                return (date2 - date1) / (1000 * 60 * 60 * 24);
                return months;
            }
    
            //function getLeapYear
    
            function difference(d1, d2) 
            {
                var hiredate, dob; var diff = 18 * 12;
                hiredate = document.getElementById(d1).value;
                dob = document.getElementById(d2).value;
                var Age = getDays(hiredate, dob);
                var compareVal = 365 * 18; //getCompareVal(hiredate,dob);
    
                if (Age >= compareVal) {
                    return true;
                    //true
                } else {
                    return false; //false
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm validating a user-entered date string in YYYY-MM-DD format using Zend_Validate::is($value,'Date') . This call
Is there a way (without installing any libraries) of validating XML using a custom
I am validating a zip code using Javascript that is generated server-side, and injected
Are there any tools available for validating a database schema against a set of
I'm investigating an annotation-based approach to validating Spring beans using spring modules . In
I am using the jQuery Validation plugin and have an issue validating items that
I'm using the following code to check if a valid date has been typed
I need to perform some date operations in ASP.net using C#. The date i
I am using Jquery valdiation plugin for validating the form at client side. I
Last week I implemented a date validation in our front end, a combination of

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.