浏览代码

Fix Issues #113 and #121 - handle the first character entered so that negatives or numbers replace an existing '0'

Cory Prowse 13 年之前
父节点
当前提交
f553bc554f
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      js/jquery.inputmask.numeric.extensions.js

+ 5 - 1
js/jquery.inputmask.numeric.extensions.js

@@ -53,6 +53,10 @@ Optional extensions on the jquery.inputmask base
                         var cbuf = buffer.slice();
                         cbuf.splice(pos, 0, chrs);
                         var bufferStr = cbuf.join('');
+                        if (/^0[\d|-]$/.test(bufferStr)) { //handle first char
+                            buffer[0]= "";
+                            return { "pos": 1, "c": "" };
+                        }
                         var isValid = opts.regex.number(separatorExpression(), opts.groupSize, radixPointExpression(), digitExpression()).test(bufferStr);
                         if (!isValid) {
                             if (strict) { //shiftL & shiftR use strict only validate from 0 to position
@@ -109,4 +113,4 @@ Optional extensions on the jquery.inputmask base
             alias: "decimal"
         }
     });
-})(jQuery);
+})(jQuery);