Inputs, keypress, change, blur and auto-format

Inputs, keypress, change, blur and auto-format

Hi there!

Well, what I'm trying to: auto-format an input type as user writes down
Suppose a form input, type text, which will cotain numbers, and I want to format them with the correct number format; i.e.: (EU format) "2222,222" --> "2.222,222" // (US format) "2222.222" --> "2,222.222"

Ok.
So I'm developing my own jQuery plugin "numberFormat" which registers for any object the listeners for keypress, change and blur events.

Right now, I can format the number as the user is writting down or changes the focus to another element.

The main issue cames whenever I try to modify a text that is already formatted.
Example:
1. First I type the number: "2222", in EU format will be "2.222"
2. Then I change focus from input to another element of the web, and the text of the input get its format.
3. Next, I modify the text, tipping down an extra '3' at the beginning, so the number should result as "32.222"
And the question is:
How I know in which position of the current value array is the new char going to be?

- I didn't know it was imposible, so far I wouldn't had achieved it. -