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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:09:27+00:00 2026-05-27T09:09:27+00:00

In my MVC 2 application, I have many views with many, many input fields.

  • 0

In my MVC 2 application, I have many views with many, many input fields. Quite a lot of them contain DateTime variables.

I am using the datepicker jQuery plugin to help the user select the date. This also allows me to do the following in my MasterPage:

$(document).delegate(".hasDatepicker", "keyup", function () {
            this.value = this.value.replace(/[^0-9\.\/]/g, '');
});

This is to eliminate users from using incorrect characters if they prefer to type. Since Datepicker adds its own class to datepicker-elements, I was able ot use that class to automatically clean up input.
No issues here, This is the part that works like it should.

The problem however, is that when I open an Edit view, the Textbox is populated with “21/05/2012 0:00:00”. Once you start using the Datepicker plugin, it gets changed to only the date, as it should.
To remove the Time-part from the textbox, I was thinking about doing:

$(".hasDatepicker").each( function() {
     $(this).val($this.val().replace(" 0:00:00",""));
});

Which seems to me to be the easiest solution.

But then I would have to add it to every page, and I was wondering if there is a way to make a .delegate() version of this. Something along the lines of

$(document).delegate(".hasDatepicker", SOME_EVENT, function () {
            $(this).val($this.val().replace(" 0:00:00",""));
});

The problem is, what should SOME_EVENT be? I want this to be triggered when the “hasDatepicker” class has been added, so that I know which textboxes to clear (there are other textboxes for remarks etc that also contain that string, but these should not be replaced.

Is there such an event that triggers on class change?
Or any other way to solve this without me having to copy paste it on every page? 🙂

  • 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-27T09:09:28+00:00Added an answer on May 27, 2026 at 9:09 am

    why do you use this complex way to edit the date format when jQuery datepicker has a builtin functionality doing just that using the dateFormat option:

    fro jquery ui docs:

    The format for parsed and displayed dates. This attribute is one of
    the regionalisation attributes. For a full list of the possible
    formats see the formatDate function.

    Code examples

    Initialize a datepicker with the dateFormat option specified.
    $( ".selector" ).datepicker({ dateFormat: 'yy-mm-dd' });
    Get or set the dateFormat option, after init.
    //getter
    var dateFormat = $( ".selector" ).datepicker( "option", "dateFormat" );
    //setter
    $( ".selector" ).datepicker( "option", "dateFormat", 'yy-mm-dd' );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MVC application view that is generating quite a large HTML table
I have an MVC application which has a set of fields for contact details
.Net MVC application also running Linq-to-SQL. I have seen many articles on grids that
I'd like to implement ASP.Net MVC application which could have controllers, views and content
I'm looking to build an ASP.NET MVC application where many screens will have multiple
Asp.net MVC2: I have many dropdownlists in my mvc application. At first, I started
We have a MVC3 application that we have created many small actions and views
In a typical MVC application we have validation that occurs in many different places.
in my MVC application I have a controller (ProjectController) which has an action (create).
In my ASP .NET MVC application i have a link that refreshes the preview

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.