title: Check Consecutive 13 digits in java
body: <p>Hi All I'm using the following function to check the Consecutive digits in java</p>
  
  <p>The issue im facing here is it works for the first Consecutive digits only </p>
  
  <p><strong>For example</strong> it work for <strong>123456789123456XXXX</strong> 
  but want this to work Consecutive any where
  <strong>XXXX123456789123456</strong> or <strong>XX123456789123456XX</strong></p>
  
  <p><strong>Update</strong></p>
  
  <p>Now if i found 13 Consecutive digits then i need to pass all Consecutive digits to the mask function</p>
  
  <p>and my result should be 
  something like this</p>
  
  <p>for input <strong>123456789123456XXXX</strong> result should be <strong>123456%%%%%3456XXXX</strong></p>
  
  <p>for input <strong>XXXX123456789123456</strong> result should be <strong>XX123456%%%%%3456XX</strong></p>
  
  <p>Please help me to solve this</p>
  
  <p><strong>My Code</strong></p>
  
  <pre><code>public void checkPosCardNoAndMask(String cardNo) {
      String maskNumber = "";
      String starValue = "";
      boolean isConsecutive = false;
      int checkConsecutive = 0;
      for (int i = 0, len = cardNo.length(); i &lt; len; i++) {
          if (Character.isDigit(cardNo.charAt(i))) {
              maskNumber = maskNumber + cardNo.charAt(i);
          } else {
              if (checkConsecutive &gt;= 13)
                  isConsecutive = true;
              else
                  break;
              starValue = starValue + cardNo.charAt(i);
          }
          checkConsecutive++;
      }
      if (isConsecutive)
      {
       cardNo = maskCCNumber(maskNumber) + starValue;
       System.out.printIn("Consecutive found!!:"+cardNo);
      }
      else
      {
       System.out.printIn("Consecutive not found!!:"+cardNo);
      }
  
  } 
  </code></pre>
  
  <p><strong>Masking logic</strong></p>
  
  <pre><code>public String maskCCNumber(String ccNo)
      {
          String maskCCNo = "";
          for (int i = 0; i &lt; ccNo.length(); i++)
          {
              if (i &gt; 5 &amp;&amp; i &lt; ccNo.length() - 4)
              {
                  maskCCNo = maskCCNo + '%';
              }
              else
              {
                  maskCCNo = maskCCNo + ccNo.charAt(i);
              }
          }
          return maskCCNo;
      }
  </code></pre>