JavaScript 屏蔽输入v1.0
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript 屏蔽输入v1.0相关的知识,希望对你有一定的参考价值。
/**************************************
* Jonas Raoni Soares Silva
* http://www.joninhas.ath.cx
**************************************/
//========================================================
// REQUIRES http://www.jsfromhell.com/geral/event-listener
//========================================================
MaskInput = function(f, m){ //v1.0
function mask(e){
var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[À-ÿ]/i, "8": /./ },
rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
function accept(c, rule){
for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
if(r & i && patterns[i].test(c))
break;
return i <= r || c == rule;
}
var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
}
for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
addEvent(f, i, mask);
};
以上是关于JavaScript 屏蔽输入v1.0的主要内容,如果未能解决你的问题,请参考以下文章
JavaScript 屏蔽输入
JavaScript Javascript HTTP请求v1.0
JavaScript 总和v1.0
JavaScript 限制v1.0
JavaScript 日期格式v1.0
JavaScript 等于v1.0