SoFunction
Updated on 2025-03-03

Automatically detect digit replacement non-number regular expressions

The code is given directly:

<!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 = ;
	var plus = '';
	if((val)){
		val = (/-+/g,'');		
		plus = '-';		
	}
	val = (/\s+/g,'');	
	if(/^\.+.*$/.test(val)){
		val = '';
	}
	val = (/[^\d\.]/,'');
	val = (/(^\d+\.{1})(\d*).*/g,'$1$2');
	val = (/(^\d+\.\d{3})\d*/g,'$1');
	val = (/^[0]*(0{1})([1-9]*)(.*)/g,'$1$2$3');		
	if((val)){
		val = (/0([1-9]+)(.*)$/,'$1$2');
	}
	
	 = plus+val;
}
 </script>
</HTML>

I wrote a function that replaces non-numbers and Chinese and English commas. Friends who need it can refer to it.

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