Created
November 23, 2016 19:54
-
-
Save rudmanmrrod/5a5f3dbb1e8f0d518f9de3050a571c4e to your computer and use it in GitHub Desktop.
Separador de miles en javascript
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
function format(separator, period) { | |
var separator_break = this.toString().split(','); | |
var numeric = separator_break[0]; | |
var decimal = separator_break.length > 1 ? period + separator_break[1] : ''; | |
var reg = /(\d+)(\d{3})/; | |
while (reg.test(numeric)) { | |
numeric = numeric.replace(reg, '$1' + separator + '$2'); | |
} | |
return numeric + decimal; | |
} | |
$(document).ready(function(){ | |
$(this).on('keyup','#myinput', function(){ | |
$(this).val(format.call($(this).val().split('.').join(''),'.',',')); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment