The code that replaces all characters except Numbers and commas with js
- 2020-03-30 03:17:01
- OfStack
Replace all characters except Numbers and commas with js
<script language="javascript">
var str="asdfk,asdf345345,345345";
//Replace all characters except Numbers and commas.
str=str.replace(/[^0-9,]*/g,"");
//Remove the first comma
if (str.substr(0,1)==',') str=str.substr(1);
//Remove the second comma
var reg=/,$/gi;
str=str.replace(reg,"");
alert(str);
</script>
Results:
345345,345345
Complete code: