Skip to content

Instantly share code, notes, and snippets.

@Ashkanph
Created October 31, 2017 09:16
Show Gist options
  • Select an option

  • Save Ashkanph/c62a2cabb90de85c465223f42c443b1b to your computer and use it in GitHub Desktop.

Select an option

Save Ashkanph/c62a2cabb90de85c465223f42c443b1b to your computer and use it in GitHub Desktop.
Comma Seperated input text numbers
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Comma Seperated input text numbers</title>
</head>
<body>
<br>
<input class="number">
<script>
var el = document.querySelector('input.number');
el.addEventListener('keyup', function (event) {
if (event.which >= 37 && event.which <= 40) return;
this.value = this.value.replace(/\D/g, '')
.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment