Created
June 25, 2011 23:07
-
-
Save pielgrzym/1047003 to your computer and use it in GitHub Desktop.
Simple plugin to format numbers in input fields on the fly (like: 10000 -> 10 000)
This file contains 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($){ | |
$.fn.extend({ | |
formatInput: function(settings) { | |
var $elem = $(this); | |
settings = $.extend({ | |
errback: null | |
}, settings); | |
$elem.bind("keyup.filter_input", $.fn.formatEvent); | |
}, | |
formatEvent: function(e) { | |
var elem = $(this); | |
var initial_value = elem.val(); | |
elem.val($.fn.insertSpaces(initial_value)); | |
}, | |
insertSpaces: function(number) { | |
return number.replace(" ", "").replace(/(\d)(?=(?:\d{3})+$)/g, "$1 "); | |
} | |
}); | |
})(jQuery); |
Hi, I just created this account because I used your code and found some cool ways to improve it.
I'm really new to Git, so I don't know what's the best way to pass the code up to you.
I forked your gist and altered it the way I have it on my project.
Here is the link for it: https://gist.github.com/RicardoJorge/8525653
If there is a better way to push the code to you (in case you like it), please let me know.
And thank you for that code, it was really was exactly what I was looking for.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool, but not support decimal like 10000.00 =(