调用的时候使用 onkeydown="return functionName(this,event.keyCode)" 禁止使用粘贴功能 onpaste = "return false;" 浮点型 [ html] //只能输入浮点型 function PositiveDoble(element, keyCode) { if (keyCode == 9 || keyCode == 116 || (keyCode >= 35 && keyCode <= 40)) { return true; } if ($(element).val().length >= 1 && $(element).val() != "-" && $(element).val().toString().lastIndexOf(".") < 0 && keyCode == 110) { return true; } //输入00 if ($(element).val().length == 1 && $(element).val()=="0" && (keyCode == 96 || keyCode == 48)) { return false; } //输入-0 if ($(element).val().length == 2 && $(element).val() == "-0" && (keyCode == 96 || keyCode == 48)) { return false; } if ($(element).val().length == 0 && (keyCode == 189 || keyCode == 109)) { return true; } if ($(element).val().length == 0 && (keyCode == 96 || keyCode == 48)) { return true; } return (keyCode >= 96 && keyCode <= 105 || keyCode == 8 || (keyCode >= 48 && keyCode <= 57)); } [html] //只能输入正整数 function PositiveInteger(element, keyCode) { if (keyCode == 9 || keyCode == 116 || (keyCode >= 35 && keyCode <= 40)) { return true; } if ($(element).val().length == 0 && (keyCode == 96 || keyCode==48)) { return false; } return (keyCode >= 96 && keyCode <= 105 || keyCode == 8 || (keyCode >= 48 && keyCode <= 57)); } [html] //只能输入英文+空格 function PositiveEnglish(keyCode) { if (keyCode == 9 || keyCode == 116 || (keyCode >= 35 && keyCode <= 40)) { return true; } return ((keyCode >= 65 && keyCode <= 90) || keyCode == 32 || keyCode==8); } [html] //带负号的 整数function PositiveInteger2(element, keyCode) { if ($(element).val().length == 1 && $(element).val() != "-" && $(element).val() != "0" && (keyCode == 96 || keyCode == 48)) { return true; } if (keyCode == 9 || keyCode == 116 || (keyCode >= 35 && keyCode <= 40)) { return true; } if ($(element).val().length == 0 && (keyCode == 189 || keyCode == 109)) { return true; } if ($(element).val().length == 0 && (keyCode == 96 || keyCode == 48)) { return true; } if ($(element).val().length == 1 && (keyCode == 96 || keyCode == 48)) { return false; } return (keyCode >= 96 && keyCode <= 105 || keyCode == 8 || (keyCode >= 48 && keyCode <= 57)); } 中文这里 使用 keypup="functionname(this)" [html] //只能输入中文 function PositiveChina(element) { $(element).val($(element).val().replace(/[^\u4e00-\u9fa5]/g, '')); }