Skip to content

Instantly share code, notes, and snippets.

@krasnikovdev
Last active May 31, 2018 13:34
Show Gist options
  • Save krasnikovdev/8f47aa41b4beb3e3652812b038328fd2 to your computer and use it in GitHub Desktop.
Save krasnikovdev/8f47aa41b4beb3e3652812b038328fd2 to your computer and use it in GitHub Desktop.
check sum input
this.value = sum(this.value);
function sum(str) {
str=str.trim().replace(/[^\d\.]+/gi,"");
var s=str.indexOf(".",str.indexOf("."));
if(s>=0){
str=str.substr(0,s+3);
var whole = str.substr(0,s);
var fractional = str.substr(s+1, s+3).replace(/[^\d]+/gi,"");
str = whole +'.'+ fractional;
}
return str
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment