title: Regex - Credit Card validation
body: <p>I'm looking for a way to validate the beginning of a credit card pattern. So for example, let's take MasterCard. </p>
  
  <p>It says that (ref: <a href="https://www.regular-expressions.info/creditcard.html" rel="nofollow noreferrer">https://www.regular-expressions.info/creditcard.html</a>):</p>
  
  <blockquote>
    <p>MasterCard numbers either start with the numbers 51 through 55...</p>
  </blockquote>
  
  <p>I'm looking for a regex that returns true when the user enters:</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>const regex = /^5|5[1-5]/; // this is not working :(
  
  regex.test("5"); // true
  regex.test("51"); // true
  regex.test("55"); // true
  regex.test("50"); // should be false, but return true because it matches the `5` at the beginning :(</code></pre>
  </div>
  </div>
  </p>