value replace adds value incorrectly to the end of input
<p>I am trying to do a value replace in an input field. It is almost working correctly. The problem is it adds the value to the end of input when I only want it added to the one location</p>

<p>Html:</p>

<pre><code>&lt;input id="boom" value="03/15/0212" /&gt;​
</code></pre>

<p>Jquery: I have hard coded some values to keep from placing all functions</p>

<pre><code>$('#boom').on('keypress', function (e)
{
    var crs = this.selectionStart;
    var from;
    var to;
    var sub;
    _dateSection = 'month';
    var currentObj = this;
    var currentVal = $(this).val();
    var c = String.fromCharCode(e.which);
    var stringSplit = currentVal.split('/');
    switch (_dateSection) {
        case 'month':
            _currentDateValue = stringSplit[0];
            from = 0;
            to = 2;
            sub = currentVal.substring(from, to);
            break;
        case 'day':
            _currentDateValue = stringSplit[1];
            from = 3;
            to = 6;
            sub = currentVal.substring(from, to);
            break;
        case 'year':
            _currentDateValue = stringSplit[2];
            from = 6;
            to = 10;
            sub = currentVal.substring(from, to);
            break;
    };
    var check = false;
    if (!check) {
        $(currentObj).val(function (index, value)
        {
            return value.replace(sub, c);
        });
    }
});
</code></pre>

<p><a href="http://jsfiddle.net/fC8KW/5/" rel="nofollow">JsFiddle</a></p>

<p>If you add 3 to the month portion of the input which is currently populated with 03 it replaces is correctly with 3, but it also adds 3 to the end of the year. Making the year, 20123 when the year value should remain 2012. </p>

<p>The final value should be </p>

<pre><code>3/15/2012
</code></pre>

<p>not </p>

<pre><code>3/15/20123
</code></pre>

<p><b>Edit:</b></p>

<p>this code gives the same problem:</p>

<pre><code>$(currentObj).val(currentVal.replace(sub, c));
</code></pre>

<p>as does this</p>

<pre><code>var replaceValue = currentVal.replace(sub, c)
$(currentObj).val(replaceValue);
</code></pre>
