我有一个文本框,我在其中显示信用卡或银行信息.我希望它被屏蔽(在page_load事件后面的代码中),以便用户可以看到如下内容:xxxxxxxxxxxx-9999.
例如:string creditcard = 1234567812345678
我想这样显示:xxxxxxxxxxxx5678
谢谢!
Gre*_*reg 10
这样的东西可能适用于可变长度的文本:
// create 4 less x's than the credit card length.
// then append that to the last 4 characters of the credit card
new string('x', creditcard.Length - 4) + creditcard.Substring(creditcard.Length - 4);
Run Code Online (Sandbox Code Playgroud)
"xxxxxxxxxxxx" + creditcard.Remove(0,12)
Run Code Online (Sandbox Code Playgroud)
由于ISO/IEC 7812信用卡号码有16位数字.
如果信用卡不是ISO/IEC并且有另一个长度,请使用greg的答案.像AmEx一样有15位数,而Diner有14位数.(我甚至没有意识到这一点,因为在欧洲,AmEx并不常见.)
| 归档时间: |
|
| 查看次数: |
4757 次 |
| 最近记录: |