{"id":342,"date":"2018-08-10T18:44:12","date_gmt":"2018-08-10T18:44:12","guid":{"rendered":"https:\/\/sidroniolima.com.br\/blog\/?p=342"},"modified":"2018-08-10T18:44:12","modified_gmt":"2018-08-10T18:44:12","slug":"credit-card-metadata-and-validator","status":"publish","type":"post","link":"https:\/\/sidroniolima.com.br\/blog\/2018\/08\/10\/credit-card-metadata-and-validator\/","title":{"rendered":"Credit Card Metadata and Validator"},"content":{"rendered":"\n<div class=\"twitter-share\"><a href=\"https:\/\/twitter.com\/intent\/tweet?text=Credit%20card%20service%20validator%20and%20Regex.&#038;hashtags=creditcard%20%23validator%20%23elo%20%23visa%20%23master%20%23javascriptregex&#038;via=sidroniolima\" class=\"twitter-share-button\">Tweet<\/a><\/div>\n<p>Hi!<\/p>\n<p>There&#8217;s a service that validates the credit card number and returns the metadata.<\/p>\n<p>The requisition is via http and returns a json. Just like this:<\/p>\n<pre><code class=\"hljs\">curl -H <span class=\"hljs-string\">\"Accept-Version: 3\"<\/span> <span class=\"hljs-string\">\"https:\/\/lookup.binlist.net\/45717360\"<\/span>\r\n<\/code> <code class=\"hljs secondary\">{\r\n  \"<span class=\"hljs-attribute\">number<\/span>\": <span class=\"hljs-value\">{\r\n    \"<span class=\"hljs-attribute\">length<\/span>\": <span class=\"hljs-number\">16<\/span>,\r\n    \"<span class=\"hljs-attribute\">luhn<\/span>\": <span class=\"hljs-literal\">true<\/span>\r\n  }<\/span>,\r\n  \"<span class=\"hljs-attribute\">scheme<\/span>\": <span class=\"hljs-value\"><span class=\"hljs-string\">\"visa\"<\/span><\/span>,\r\n  \"<span class=\"hljs-attribute\">type<\/span>\": <span class=\"hljs-value\"><span class=\"hljs-string\">\"debit\"<\/span><\/span>,\r\n  \"<span class=\"hljs-attribute\">brand<\/span>\": <span class=\"hljs-value\"><span class=\"hljs-string\">\"Visa\/Dankort\"<\/span><\/span>,\r\n  \"<span class=\"hljs-attribute\">prepaid<\/span>\": <span class=\"hljs-value\"><span class=\"hljs-literal\">false<\/span><\/span>,\r\n  \"<span class=\"hljs-attribute\">country<\/span>\": <span class=\"hljs-value\">{\r\n    \"<span class=\"hljs-attribute\">numeric<\/span>\": <span class=\"hljs-string\">\"208\"<\/span>,\r\n    \"<span class=\"hljs-attribute\">alpha2<\/span>\": <span class=\"hljs-string\">\"DK\"<\/span>,\r\n    \"<span class=\"hljs-attribute\">name<\/span>\": <span class=\"hljs-string\">\"Denmark\"<\/span>,\r\n    \"<span class=\"hljs-attribute\">emoji<\/span>\": <span class=\"hljs-string\">\"&#x1f1e9;&#x1f1f0;\"<\/span>,\r\n    \"<span class=\"hljs-attribute\">currency<\/span>\": <span class=\"hljs-string\">\"DKK\"<\/span>,\r\n    \"<span class=\"hljs-attribute\">latitude<\/span>\": <span class=\"hljs-number\">56<\/span>,\r\n    \"<span class=\"hljs-attribute\">longitude<\/span>\": <span class=\"hljs-number\">10<\/span>\r\n  }<\/span>,\r\n  \"<span class=\"hljs-attribute\">bank<\/span>\": <span class=\"hljs-value\">{\r\n    \"<span class=\"hljs-attribute\">name<\/span>\": <span class=\"hljs-string\">\"Jyske Bank\"<\/span>,\r\n    \"<span class=\"hljs-attribute\">url<\/span>\": <span class=\"hljs-string\">\"www.jyskebank.dk\"<\/span>,\r\n    \"<span class=\"hljs-attribute\">phone<\/span>\": <span class=\"hljs-string\">\"+4589893300\"<\/span>,\r\n    \"<span class=\"hljs-attribute\">city<\/span>\": <span class=\"hljs-string\">\"Hj\u00f8rring\"<\/span>\r\n  }\r\n<\/span>}\r\n<\/code><\/pre>\n<p>The link: <a href=\"https:\/\/binlist.net\/\">https:\/\/binlist.net\/<\/a><\/p>\n<p>But if you want regex for the most common credit card brands, check below.<\/p>\n<div>\n<div>\u00a0\u00a0\u00a0\u00a0const elo = \/((((636368)|(438935)|(504175)|(451416)|(636297)))[0-9]{4}$)|(((5067)|(4576)|(4011))[0-9]{8}$)$\/;<\/div>\n<div>\u00a0\u00a0\u00a0\u00a0const visa = \/^4[0-9]{12}(?:[0-9]{3})$\/;<\/div>\n<div>\u00a0\u00a0\u00a0\u00a0const master = \/^5[1-5][0-9]{14}$\/;<\/div>\n<div>\u00a0\u00a0\u00a0\u00a0const amex = \/^3[47][0-9]{13}$\/;<\/div>\n<div>\u00a0\u00a0\u00a0\u00a0const diners = \/^3(?:0[0-5]|[68][0-9])[0-9]{11}$\/;<\/div>\n<div>\u00a0\u00a0\u00a0\u00a0const discover = \/^6(?:011|5[0-9]{2})[0-9]{12}$\/;<\/div>\n<div>\u00a0\u00a0\u00a0\u00a0const jcb = \/^(?:2131|1800|35\\d{3})\\d{11}$\/;<\/div>\n<div><\/div>\n<div>That&#8217;s it!<\/div>\n<\/div>\n\n<div class=\"twitter-share\"><a href=\"https:\/\/twitter.com\/intent\/tweet?text=Credit%20card%20service%20validator%20and%20Regex.&#038;hashtags=creditcard%20%23validator%20%23elo%20%23visa%20%23master%20%23javascriptregex&#038;via=sidroniolima\" class=\"twitter-share-button\">Tweet<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hi! There&#8217;s a service that validates the credit card number and returns the metadata. The requisition is via http and returns a json. Just like this: curl -H &#8220;Accept-Version: 3&#8221; &#8220;https:\/\/lookup.binlist.net\/45717360&#8221; { &#8220;number&#8221;: { &#8220;length&#8221;: 16, &#8220;luhn&#8221;: true }, &#8220;scheme&#8221;: &#8220;visa&#8221;, &#8220;type&#8221;: &#8220;debit&#8221;, &#8220;brand&#8221;: &#8220;Visa\/Dankort&#8221;, &#8220;prepaid&#8221;: false, &#8220;country&#8221;: { &#8220;numeric&#8221;: &#8220;208&#8221;, &#8220;alpha2&#8221;: &#8220;DK&#8221;, &#8220;name&#8221;: &#8220;Denmark&#8221;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,52,6],"tags":[78,82,81,79,80],"class_list":["post-342","post","type-post","status-publish","format-standard","hentry","category-curiosidade","category-javascript","category-sistema-de-informacao","tag-creditcard","tag-elo","tag-master","tag-validator","tag-visa"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/posts\/342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/comments?post=342"}],"version-history":[{"count":3,"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/posts\/342\/revisions"}],"predecessor-version":[{"id":345,"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/posts\/342\/revisions\/345"}],"wp:attachment":[{"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/media?parent=342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/categories?post=342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sidroniolima.com.br\/blog\/wp-json\/wp\/v2\/tags?post=342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}