Search code examples
jqueryasp.net-mvc-2maskingjquery-mask

jQuery + MVC + DateTime Format


In my aspx:

<td class="data"><%= Html.TextBoxFor(model => model.LastContainerStartDate)%></td>

where lastContainerStartDate is of dataType DateTime

and in

 $(document).ready(function () {
           $("#LastContainerSeqNum").numeric();
           $("#LastContainerStartDate").mask("99/99/9999 99:99:99");
           $("#LastContainerEndDate").mask("99/99/9999 99:99:99");

when the page get loads => only loads the date with full mask format

Ex: 10/01/2010 loads fine. 01/01/2010 comes with blank field

How can i make my mask format for first char optional.


Solution

  • First - I suggest that you add a tag to this post clarifying which plugin this involves, because .mask is not a native method for JQuery.

    Second - could you please clarify your question?

    Ex: 10/01/2010 loads fine. 01/01/2010 comes with blank field

    It seems that you are trying to input 01/01/2010, which should be legal input given that mask, and I was able to input that data, and retrieve it from the db (and populate correctly) in my own testing.

    But then you ask:

    How can i make my mask format for first char optional.

    Could you specify what exactly you are looking for? Are you looking to make the input accept a string like 1/1/2010, or are you having problems making it accept the leading zero?