<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<input id="qwe" type="text" />
<script type="text/javascript">
$('#qwe').keyup(function(e){
  var str = '', value = $(this).val().match(/\d/g);
  if(!value) return;
  for(var i = 0; i < value.length; i++){
    if(i%3==0) str += ' ';
    str += value[i];
  }
  $('#qwe').val(str);
});
</script>