DDR爱好者之家 Design By 杰米

直接给出代码了:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
 <TITLE> New Document </TITLE>
 <META NAME="Generator" CONTENT="EditPlus">
 <META NAME="Author" CONTENT="">
 <META NAME="Keywords" CONTENT="">
 <META NAME="Description" 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>

写的一个替换 非数字与中英文逗号的函数,需要的朋友可以参考一下

function renumdou(str){
var regexp = /[^\d,,]]*/g;
newstr=str.replace(regexp,"");
return newstr
}

DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米