0

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()?

dawriter
  • 425
  • 3
  • 8
  • 21

1 Answers1

1

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.

Joe
  • 25,000
  • 3
  • 22
  • 44
  • Hi - I tried this in MVC 4 - added a regular expression in the model and in jquery code behind did the $('#datefield').inputput("Regex"); -- it didn't accept any input.. – dawriter Jun 06 '14 at 17:05
  • `.inputput` looks like a typo. Here's a [demo fiddle](http://jsfiddle.net/Fd86c/) – Joe Jun 06 '14 at 19:19