title: Masking last 4 digits in JavaScript
body: <p>Here I am using regex pattern to mask last 4 digits for Credit Card number.</p>
  
  <pre><code>$("#ccnumber").html(ccnbr); //ccnumber refers to div ID
  
  $("#ccnumber").text(function(_, val) {
    return val.replace(/\d{12}(\d{4})/, "************$1");
  });
  </code></pre>
  
  <p>It is applicable for only 16 digit credit card numbers. But, I need to mask the incoming numbers (may be 10 or 11) by <code>*</code> and show the last 4 digits. </p>
  
  <p>Is it possible in javascript/jQuery?</p>
  
  <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>$('#ccnumber').text(function(_, val) {
    return val.replace(/\d{12}(\d{4})/, "************$1");
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div id="ccnumber"&gt;1234567891234567&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>