Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The rules you have provided don't actually fully validate credit card numbers, they just check for the correct number of digits.</p> <p>If you really want to validate credit card numbers, you'll need to ensure that the <em>check digit</em> (the last digit) matches the rest of the number according to the <a href="http://en.wikipedia.org/wiki/Luhn_algorithm" rel="nofollow">Luhn algorithm</a> - more info, and working code in Javascript, is <a href="http://evolt.org/node/24700" rel="nofollow">available here</a>. Using the regular expressions you provided, <code>4000000000000000</code> is treated as a valid VISA card number but when you check the <em>check digit</em> as well, it isn't.</p> <p>To explain the regular expressions you provided:</p> <p><code>^</code> means the beginning of the string and <code>$</code> means the end. These must always be used to anchor your regular expressions, unless you want it to match on a substring of a larger string.</p> <p><code>[0-9]</code> means any digit (0 to 9 or anything in between). You could also use <code>\d</code> for this (which one of your other examples does). <code>\d</code> is a special character which means "any digit". There are several other such special characters such as <code>\s</code> which means "any whitespace character".</p> <p><code>{12}</code> means repeat the previous letter or bracketed pattern 12 times (no more, no less).</p> <p><code>(?:</code> just begins a bracketed pattern. The difference between <code>(?:</code> and <code>(</code> is that <code>(?:</code> doesn't capture the pattern for retrieval later (using a back reference). None of these examples use back references so <code>(?:</code> is fine (and is usually more efficient).</p> <p><code>)</code> ends a bracketed pattern. Bracketed patterns are just for putting multiple letters/patterns into a group.</p> <p><code>?</code> means that the previous letter, or bracketed pattern, is <em>optional</em> - it can be present either 0 or 1 times. Incidentally, <code>{0,1}</code> would do the same thing.</p> <p>The rest is pretty self-explanatory, except for:</p> <p><code>[68]</code> which means <em>either</em> 6 <em>or</em> 8. If it had a dash in there, like <code>[6-8]</code>, it would mean 6 <em>to</em> 8, which would include 7 as well. But it doesn't, so it excludes 7.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload