<input id="input">
<script>(function(){
var handler = function(data){
return data.split(/(\d{3})/).join(' ').replace(/\s+/g, ' ').replace(/^\s+/, '').replace(/\s+$/, '');
}, lastValue = '', input = document.getElementById('input');
if(input.addEventListener)input.addEventListener('input', function(){
this.value = handler(this.value);
}, false);
else if(input.attachEvent) input.attachEvent('onpropertychange', function(){
if(window.event.propertyName == 'value' && window.event.propertyName != lastValue){
this.value = lastValue = handler(this.value);
}
});
}());</script>
Где то так.
Что то кривая регулярка вышла %)