Search code examples
jquerymaskedinput

JQuery Mask Input


I've used Jquery masked input but I just came across an interesting requirement. The user wants to save a series of dates on a single field. They want to enter the dates like this:

10/10/2013; 12/12/2004; 10/30/2003

The field naturally would be saved for coma delimited purposes BUT after each ; the masking of the dates 99/99/9999 should apply...

Has anyone tried this with regex or inputmask()?


Solution

  • If you are using inputmask version 3+, you could use a regular expression. Something like:

    <input id="multidate" type='text' data-inputmask-regex="([0-9][0-9]/[0-9][0-9]/[0-9]{4}[ ;]+)*" />
    

    and in the onload:

    $("#multidate").inputmask("Regex");
    

    It won't prefill the slash like __/__/____, so you'll have to type them yourself, but it will enforce the format.