4

I'm using Robin Herbot's excellent jQuery Input Masks plugin. [ https://github.com/RobinHerbots/jquery.inputmask ]. It's quite complete and seems to have everything I need, but I can't seem to figure one thing out.

How do I create a mask like: "mm/dd/yyyy hh:mm pm" where both the date portion and the time portion work like the "date" and "time" masks work?

I can use date or time, but datetime uses the European dd/mm format rather than the mm/dd format I need. I've tried several permutations, but I'm clearly missing something and the documentation takes a lot for granted.

pbarney
  • 2,529
  • 4
  • 35
  • 49

3 Answers3

6

jQuery Input Mask

$('#InputID').inputmask({
        mask: "2/1/y h:s t\\m",
        placeholder: "mm/dd/yyyy hh:mm xm",
        alias: "datetime",
        hourFormat: "12"
    });

Check other aliases.

War10ck
  • 12,387
  • 7
  • 41
  • 54
Bob
  • 76
  • 1
2

Go here: http://digitalbush.com/projects/masked-input-plugin/

Use this:

$('#InputID').mask("99/99/9999 99:99 aa");

You're welcome.

user2687646
  • 264
  • 1
  • 5
  • 12
  • I've tried this mask, and the problem with it is that it accepts ANY digit for the first character while the "date" alias knows to only put a 0 or 1 there. If the user presses 8, it puts a 0 in the first position and the 8 in the second position. – pbarney Jan 28 '14 at 14:01
0

Maskedinput plugin is the best solution for datetime type input - simply and lightweight.

As for "accepting ANY digit": you can easy modificate base js library regex by adding your own rules:

{ definitions: { 9: "[0-9]", 1: "[0-1]", 2: "[0-2]", a: "[A-Za-z]", "*": "[A-Za-z0-9]" }

arghtype
  • 4,376
  • 11
  • 45
  • 60
Dunadan
  • 23
  • 1
  • 7