正则表达式信用卡号测试 [英] Regex credit card number tests

查看:44
本文介绍了正则表达式信用卡号测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试一个正则表达式模式匹配信用卡的应用程序,然后应该突出显示这些数字.我正在使用网站 http://regexpal.com/ 为我的测试创建测试信用卡号.我的要求是拥有有效的信用卡号码,它们之间可以有-"和/或,".我没有成功建立这样的号码,因为我使用该网站对其进行测试

I'm testing one application where Regex pattern match credit card then such numbers should be highlighted. I'm using site http://regexpal.com/ to create test credit credit card numbers for my testing. my requirement is to have valid credit card numbers which can have "-" and/or "," between them.I was not successful to build such a number as when i test it using the site

http://regexpal.com.

我需要一些具有以下场景的信用号码

I need few credit numbers with scenarios below

  1. 有效的信用卡号,任何数字之间可以有-".
  2. 有效的信用卡号,在任何数字之间可以有,".
  3. 有效的信用卡号,可以在任意数字之间组合,"或-".

推荐答案

首先从字符串中删除所有 - 和其他非数字.

Remove all , and - and other non-digits from the string first.

然后使用这个匹配 Visa、MasterCard、American Express、Diners Club、Discover 和 JCB 卡的正则表达式:

Then use this regex that matches Visa, MasterCard, American Express, Diners Club, Discover, and JCB cards:

^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$

这篇关于正则表达式信用卡号测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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