<input onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 &&
(event.keyCode<48 || event.keyCode>57)) event.returnValue=false">
11. 只能输入两位小数,三位小数(有闪动)
复制代码 代码如下:
<input maxlength=9
onkeyup="if(value.match(/^/d{3}$/))value="/value.replace(value,parseInt(value/10))"
;value="/value.replace(//./d*/./g,'."')" onKeyPress="if((event.keyCode<48
|| event.keyCode>57) && event.keyCode!=46 && event.keyCode!=45 ||
value.match(/^/d{3}$/) || //./d{3}$/.test(value))
{event.returnValue=false}" id=text_kfxe name=text_kfxe>
12、只能输入数字与逗号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META CONTENT="EditPlus"> <META CONTENT=""> <META CONTENT=""> <META CONTENT=""> </HEAD> <BODY> <input onkeyup='check(this)'/> </BODY> <script> function check(obj){ var sreg = /^-+.*/g; var zero = /^0[1-9]+\.*\d*/g; var val = obj.value; var plus = ''; if(sreg.test(val)){ val = val.replace(/-+/g,''); plus = '-'; } val = val.replace(/\s+/g,''); if(/^\.+.*$/.test(val)){ val = ''; } val = val.replace(/[^\d\.]/,''); val = val.replace(/(^\d+\.{1})(\d*).*/g,'$1$2'); val = val.replace(/(^\d+\.\d{3})\d*/g,'$1'); val = val.replace(/^[0]*(0{1})([1-9]*)(.*)/g,'$1$2$3'); if(zero.test(val)){ val = val.replace(/0([1-9]+)(.*)$/,'$1$2'); } obj.value = plus+val; } </script> </HTML>
13、替换内容中的非数字与中英文以外的字符
function renumdou(str){ var regexp = /[^\d,,]]*/g; newstr=str.replace(regexp,""); return newstr }
您可能感兴趣的文章: