我有2个文本区域,我想应用遮罩。jquery遮罩的邮政编码插件
- 文本区域1:多用逗号和空间
- 文本区域2分离5位邮政编码:多个3位拉链通过在这两种情况下一个逗号和空间
所以分离代码,允许的字符是0-9和逗号和空格。
我很难为此提出掩蔽。我可以用蒙面插件做这样的事吗?
http://digitalbush.com/projects/masked-input-plugin/
我跟着this拿出一个自定义插件,允许特定的密钥,但得到了与逗号和Ctrl + V的问题。逗号和<都具有相同的密钥代码,所以现在采取掩蔽路线。
//Multiple zip codes separated by comma and space
jQuery.fn.multipleZipCodesSeparatedByCommaAndSpaceOnly = function() {
return this.each(function() {
$(this).keydown(function (e) {
var key = e.which || e.keyCode;
//alert(String.fromCharCode(key));
if (!e.altKey && e.ctrlKey && //&& !e.shiftKey &&
// numbers
(key >= 48 && key <= 57) ||
// Numeric keypad
(key >= 96 && key <= 105) ||
// comma, space
key == 188 || key == 32 ||
// Backspace and Tab
key == 8 || key == 9 ||
// Home and End
key == 35 || key == 36 ||
// left and right arrows
key == 37 || key == 39 ||
// Del and Ins
key == 46 || key == 45) {
return true;
}
return false;
});
});
};
谢谢,我把下面这样我可以正常格式化我的实现。 –