Instantly share code, notes, and snippets.

@gknasln /dabblet.css
Last active Oct 13, 2018

Embed
What would you like to do?
Untitled
input{
width: 200px;
height: 20px;
padding-left: 10px;
margin: 50px;
}
<div class="container">
<input type="text" >
</div>
document.querySelector('input').addEventListener('keydown', function(e){
e.preventDefault();
if(e.keyCode > 48 && e.keyCode < 57){
var value = this.value.replace(/,/g, "");
value += e.key;
const newValue = value.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
this.value = newValue;
}else{
if(e.key == 'Backspace'){
var value = this.value.replace(/,/g, "");
value = value.substr(0, value.length-1);
const newValue = value.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
this.value = newValue;
}
}
});
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"javascript"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment