Strip spaces before performing Luhn check
<p>I have a function that performs a Luhn check on a card entry when a form is posted.</p>

<pre><code>&lt;script language="javascript"&gt;
 function Calculate(Luhn)
{
var sum = 0;
for (i=0; i&lt;Luhn.length; i++ )
{
    sum += parseInt(Luhn.substring(i,i+1));
}
var delta = new Array (0,1,2,3,4,-4,-3,-2,-1,0);
for (i=Luhn.length-1; i&gt;=0; i-=2 )
{       
    var deltaIndex = parseInt(Luhn.substring(i,i+1));
    var deltaValue = delta[deltaIndex]; 
    sum += deltaValue;
}   
var mod10 = sum % 10;
mod10 = 10 - mod10; 
if (mod10==10)
{       
    mod10=0;
}
return mod10;
}

function Validate(Luhn)
{
var LuhnDigit = parseInt(Luhn.substring(Luhn.length-1,Luhn.length));
var LuhnLess = Luhn.substring(0,Luhn.length-1);
if (Calculate(LuhnLess)==parseInt(LuhnDigit))
{
    return true;
}
alert("\n\nYou have mis-typed your card number! \nPlease check and correct.\n\n")   
return false;
}
</code></pre>

<p>I also have a function that removes any spaces that may have been entered in the card number onblur.</p>

<pre><code>function stripChar(sValue, sChar) {
var i, tempChar, buildString;
buildString = ""
for (var i=0; i&lt;sValue.length; i++) {
    tempChar = sValue.charAt(i);
    if (tempChar != sChar) {
        buildString = buildString + tempChar;
    }
}
return buildString;
</code></pre>

<p>How do I combine the functions so that the spaces are removed and the card number checked onblur.</p>
