[英]Can I get the last 4 digits of a regex credit card number?
我有這種用於 AMEX 信用卡格式的正則表達式模式 - (?<?\d)3[47][0-9]{13}(.?\d)。 有沒有辦法獲取最后 4 個字符或數字?
我正在嘗試屏蔽信用卡,以防在表單中插入信用卡格式。 因此,不會插入信用卡,而是會詢問諸如 **** **** **** 1234 之類的問題
它可以是 16 位或更多的信用卡,因此您可以使用此正則表達式匹配它,或者您可以轉到此鏈接並生成您自己的正則表達式
Regex (?i)^((\d+\s+?\d+\s+?\d+\s+?)(\d{4}))
在這里訪問 Group2
var Creditcardno= // Here put your credit card no
string reg = @"(?i)^((\d+\s+\d+\s+\d+\s+)(\d{4})))";
Regex r = new Regex(reg, RegexOptions.IgnoreCase);
Match m = r.Match(Creditcardno);
int number = m.Groups[2];
您可以通過對正則表達式進行分組來獲得最后四個 no 或任何內容。
如果你只需要最后四位數而已
(.+)([0-9]{4}$)
使用它,從第1組中你可以得到最后四個沒有。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.