JQuery masked input - date format as m / d / yyyy or m / dd / yyyy or mm / dd / yyyy or mm / d / yyyy

I want to use the jQuery built-in input plugin found here http://digitalbush.com/projects/masked-input-plugin/ to format the date.

I am retrieving data from the database to populate the date field when the page loads. Then the user will be able to change the date if it is incorrect.

I want people to be able to enter only one number per month and day, instead of entering 0 to a single digit. I want them to be able to print on 6/13/2010 instead of 06/13/2010. However, data from the database may not be ahead.

I know everything that is listed after? is optional, but I want the characters at the beginning or middle to be optional.

Thank!

+3
source share
3 answers

I had a similar requirement lately, and the only thing I could find was that I didn’t require me to work hard on setting up the plugin, it was to use this modified date masking plugin based on what you mentioned . He seems to be doing this job so far.

If you want to check it out, go to this page .

The main implementation that we used with this modified date timer is as follows:

$('#yourInputBoxHere').mask("99/99/9999", {placeholder: 'MM/DD/YYYY' });

I have not tried it with single digits for dates, but if I did, I would just change the expression above:

$('#yourInputBoxHere').mask("9/9/9999", {placeholder: 'M/D/YYYY' });

Hope this helps.

+2
source

, , https://github.com/RobinHerbots/jquery.inputmask:

$('#yourInputBoxHere').datepicker().inputmask("date", { placeholder: "mm/dd/yyyy", yearrange: { minyear: 1700 } });

"0" , , "1", , 3, "0" .

yearrange maxyear, .

.datepicker(), jquery.

, !

+1

: .

, jquery ui datepicker.

, :

$("#texbox1").datepicker();

, .

, .

0

All Articles