Browse Source

add mm.dd.yyyy & mm-dd-yyyy date aliases

Robin Herbots 13 years ago
parent
commit
53e1178d74
1 changed files with 21 additions and 7 deletions
  1. 21 7
      js/jquery.inputmask.extentions.js

+ 21 - 7
js/jquery.inputmask.extentions.js

@@ -3,7 +3,7 @@ Input Mask plugin extentions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2012 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 1.0.1
+Version: 1.0.2
 
 Optional extentions on the jquery.inputmask base
 */
@@ -180,8 +180,8 @@ Optional extentions on the jquery.inputmask base
                     mask: "m/d/y",
                     placeholder: "mm/dd/yyyy",
                     regex: {
-                        day: new RegExp("((0[1-9]|1[012])\/(0[1-9]|[12][0-9]))|((0[13-9]|1[012])\/30)|((0[13578]|1[02])\/31)"),
-                        daypre: new RegExp("((0[13-9]|1[012])\/[0-3])|(02\/[0-2])"),
+                        day: function(separator) { return new RegExp("((0[1-9]|1[012])\\" + separator + "(0[1-9]|[12][0-9]))|((0[13-9]|1[012])\\" + separator + "30)|((0[13578]|1[02])\\" + separator + "31)")},
+                        daypre: function(separator) { return new RegExp("((0[13-9]|1[012])\\" + separator + "[0-3])|(02\\" + separator + "[0-2])")},
                         month: new RegExp("0[1-9]|1[012]"),
                         monthpre: new RegExp("[01]"),
                         yearpre1: new RegExp("[12]"),
@@ -201,10 +201,10 @@ Optional extentions on the jquery.inputmask base
                         'd': { //day
                             validator: function(chrs, buffer, pos, strict, opts) {
                                 var monthValue = buffer.join('').substr(0, 3);
-                                var isValid = opts.regex.day.test(monthValue + chrs);
+                                var isValid = opts.regex.day(opts.separator).test(monthValue + chrs);
                                 if (!strict && !isValid) {
                                     if (chrs.charAt(1) == opts.separator[opts.separator.length -1]) {
-                                        isValid = opts.regex.day.test(monthValue + "0" + chrs.charAt(0));
+                                        isValid = opts.regex.day(opts.separator).test(monthValue + "0" + chrs.charAt(0));
                                         if (isValid) {
                                             buffer[pos - 1] = "0";
                                             buffer[pos] = chrs.charAt(0);
@@ -218,9 +218,9 @@ Optional extentions on the jquery.inputmask base
                             cardinality: 2,
                             prevalidator: [{ validator: function(chrs, buffer, pos, strict, opts) {
                                 var monthValue = buffer.join('').substr(0, 3);
-                                var isValid = opts.regex.daypre.test(monthValue + chrs);
+                                var isValid = opts.regex.daypre(opts.separator).test(monthValue + chrs);
                                 if (!strict && !isValid) {
-                                    isValid = opts.regex.day.test(monthValue + "0" + chrs);
+                                    isValid = opts.regex.day(opts.separator).test(monthValue + "0" + chrs);
                                     if (isValid) {
                                         buffer[pos] = "0";
                                         pos++;
@@ -318,6 +318,20 @@ Optional extentions on the jquery.inputmask base
                     		separator: '\-',
                          	alias: "dd/mm/yyyy"
                         },
+                        'mm.dd.yyyy': {
+                    		mask: "m.d.y",
+                    		placeholder: "mm.dd.yyyy",
+                    		leapday: "02.29.",
+                    		separator: '\.',
+                         	alias: "mm/dd/yyyy"
+                        },
+                        'mm-dd-yyyy': {
+                    		mask: "m-d-y",
+                    		placeholder: "mm-dd-yyyy",
+                    		leapday: "02-29-",
+                    		separator: '\-',
+                         	alias: "mm/dd/yyyy"
+                        },
                         'hh:mm:ss': {
                             mask: "h:s:s",
                             autoUnmask: false