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 7502019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:43:43+00:00 2026-05-29T20:43:43+00:00

This is the client script function for an asp.net validation control. <script type=text/javascript> function

  • 0

This is the client script function for an asp.net validation control.

<script type="text/javascript">
    function validateDateControl(sender, args) {

        var d = new Date(args.Value);

        args.IsValid = (Object.prototype.toString.call(d) === "[object Date]");

        if (!args.IsValid) {
            sender.innerText = "Client: Invalid date";
        }     

        return args.IsValid;
    }
</script>

Immediate Window Results:
d
NaN
Object.prototype.toString.call(d) === "[object Date]"
true

Why is the comparison evaluating True?

  • 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-29T20:43:43+00:00Added an answer on May 29, 2026 at 8:43 pm

    Because new Date('as;dlas;ld,as;dl,as') is still a Date object.

    > var d = new Date('as;dlas;ld,as;dl,as')
      undefined
    > d.toString()
      "Invalid Date"
    > Object.prototype.toString.call(d)
      "[object Date]"
    

    A better way to check date validity is to see that Date.getTime() does not return NaN:

    function validateDateControl(sender, args) {
    
        var d = new Date(args.Value);
    
        args.IsValid = !isNaN(d.getTime());
    
        if (!args.IsValid) {
            sender.innerText = "Client: Invalid date";
        }     
    
        return args.IsValid;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created ASP.NET user control with javascript function : <%@ Control Language=C# AutoEventWireup=true CodeBehind=TestControl.ascx.cs
I've seen in quite a few examples of asp.net ajax client side script the
I am trying to use the Client-side Validation with jQuery in ASP.NET MVC (2).
I need to call ASP.Net server side code from the client. Because I'm in
Label1 (asp.net control) is located inside Panel1 of my webpage and I have a
I have a C# ASP.NET app that creates a JavaScript array of values for
I've been doing C# for years but ASP.NET for not so long and this
I am having problems with code written in ASP.NET with some javascript, doing a
I have an ASP.NET page with two instances of the same Web User Control
I wrote this javascript Function : function ShowMsg(msg) { $.blockUI({ message: '<div dir=rtl align=center><h1><p>'

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.