Created
October 31, 2017 09:16
-
-
Save Ashkanph/c62a2cabb90de85c465223f42c443b1b to your computer and use it in GitHub Desktop.
Comma Seperated input text numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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