用于 JCB 信用卡验证的 Reg-Ex [英] Reg-Ex for JCB Credit Card Validation

查看:40
本文介绍了用于 JCB 信用卡验证的 Reg-Ex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用此规则进行 JCB 卡验证的 reg-ex,(JCB 格式参考)

I need a reg-ex for JCB card validation with this rule, (Reference for JCB format)

前四位数字必须是 3088、3096、3112、3158、3337 或第一个八位数字必须在 35280000 到 35899999 的范围内.有效长度:16 位.

First four digits must be 3088, 3096, 3112, 3158, 3337, or the first eight digits must be in the range 35280000 through 35899999. Valid length: 16 digits.

许多帖子都使用正则表达式 ^(?:2131|1800|35\d{3})\d{11}$ 引用 post1post2post3一>.

Many posts are found with Regex ^(?:2131|1800|35\d{3})\d{11}$ referring to post1, post2 and post3.

我正在使用 Authorize.Net 构建信用卡支付模块.但是对于上述正则表达式 (^(?:2131...),Authorize.Net 测试 JCB 信用卡验证失败.

I am building a credit card payment module using Authorize.Net.But the Authorize.Net test JCB credit card validation fails for above Regex (^(?:2131...).

但是有 JCB 卡,如 3088000000000017(Authorize.Net 测试卡)、3096022966045455,3088810779293696.

But there are JCB cards like 3088000000000017 (Authorize.Net test card), 3096022966045455,3088810779293696.

帮助我使用正则表达式.我找不到任何带有 2131 或 1800 的 JCB 卡,我是不是遗漏了什么.

Help me with the Regex. I could not find any JCB cards with 2131 or 1800, am I missing something.

推荐答案

鉴于规则我会使用这个正则表达式:

Given the rules I would use this regex:

^(3(?:088|096|112|158|337|5(?:2[89]|[3-8][0-9]))\d{12})$

细分:

  • ^(3...)$:锚定开始和结束并捕获以数字3开头的内容

  • ^(3...)$: Anchor start and end and capture the content beginning with digit 3

(?:...):不要显式捕获内容(在外括号内捕获)

(?:...): Don't capture content explicitly (captured within outer parenthesis)

088|...|337|...:匹配任意三位数值

5(?:...):先匹配 5 然后

2[89]|[3-8][0-9]:匹配 2 后跟 8 或 9,或 3 到 8 之间的任何数字后跟任何数字 (从 0 到 9)

2[89]|[3-8][0-9]: Match either 2 followed by 8 or 9, or any digit from 3 to 8 followed by any digit (from 0 to 9)

\d{12}:后跟正好 12 个任意数字(\d 与 [0-9] 相同)

\d{12}: Followed by exactly 12 any digits (\d is the same as [0-9])

关于您关于以 2131 和 1800 开头的数字的问题,它在您的第三个参考页中写道,这些 JCB 卡号的长度为 15 位,而以 35 开头的则为 16 位.如果您的规范仅涉及 16 位长数字,那么您可能不需要匹配那些较短的数字.

Regarding your question about numbers starting with 2131 and 1800, it reads in your third reference page that those JCB card numbers are 15 digits long, while ones beginning with 35 are 16 digits long. If your specifications refers to only 16 digit long numbers, then you probably won't need to match those shorter ones.

这篇关于用于 JCB 信用卡验证的 Reg-Ex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆