title: Masking credit card number if a CC number entered
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var cardNumber       = '4761640026883566';
  var cardNumberDashed = '4761-6400-1234-2345';
  var cardNumberSpaced = '4761 6400 1234 3523';
  
  var ensureOnlyNumbers  = R.replace(/[^0-9]+/g, '');
  var maskAllButLastFour = R.replace(/[0-9](?=([0-9]{4}))/g, '*');
  var hashedCardNumber   = R.compose(maskAllButLastFour, ensureOnlyNumbers);
  
  document.body.innerHTML = hashedCardNumber(cardNumber)       + '&lt;br/&gt;' + 
                            hashedCardNumber(cardNumberDashed) + '&lt;br/&gt;' + 
                            hashedCardNumber(cardNumberSpaced);</code></pre>
  </div>
  </div>
  </p>
  
  <p>My situation is a bit complicated, I have a <code>&lt;textarea&gt;</code> that I use as a message field in a chat window. <strong>I want to mask all credit card numbers that was sent on this chat, but NOT every number</strong>, because I do need a membership numbers from clients which is 10-15 digits numbers.</p>
  
  <p><code>&lt;textarea id="postMessage"&gt;&lt;/textarea&gt;</code></p>
  
  <p>I followed the code in this jsfiddle: <a href="http://jsfiddle.net/7odv6kfk/" rel="nofollow noreferrer">http://jsfiddle.net/7odv6kfk/</a> but it works only on input fields that have credit card numbers.</p>
  
  <p>How can I do that?</p>
  
  <p>Thank you!</p>