文本中允许指定的信息输入,兼容多种浏览器

与许输入整数

function AllowInputNumberNew(e) {
var key = window.event ? e.keyCode : e.which;
//8--backspace, 0--delete
if (key == 8 || key == 0) {
e.returnValue = true;
return true;
}
else {
var keychar = String.fromCharCode(key);
reg = /\d/;
var flag = reg.test(keychar);
e.returnValue = flag;
return flag;
}
}

 

允许输入float

function AllowInputFloatNew(e) {
var key = window.event ? e.keyCode : e.which;
//8--backspace, 0--delete, 46--.
if (key == 8 || key == 0 || key == 46) {
e.returnValue = true;
return true;
}
else {
var keychar = String.fromCharCode(key);
reg = /\d/;
var flag = reg.test(keychar);
e.returnValue = flag;
return flag;
}
}

 

允许输入指定字符

function AllowInputChar(e) {
var key = window.event ? e.keyCode : e.which;
if (key == 8 || key == 0 || key == 46 || key == 32 || (key >= 48 && key <= 57)) {
e.returnValue = true;
return true;
}
else {
var keychar = String.fromCharCode(key);
if (keychar == "." || keychar == "_" || keychar == "-" || keychar == "," || keychar == "(" || keychar == ")") {
return true;
} else {
reg = /^\w*[a-z]+\w*$/i;
var flag = reg.test(keychar);
e.returnValue = flag;
return flag;
}
}
}

 

不允许输入任何数据

function NotAllowInputAny(e) {
var key = window.event ? e.keyCode : e.which;
if (key == 8 || key == 0) {
e.returnValue = false;
return false;
}
else {
e.returnValue = false;
return false;
}
}

你可能感兴趣的:(浏览器)