I am having an issue when there is a space before/after in CreditCardNo. For e.g “from INV 2420852290 to SAV 0165487”. Here 2420852290 is 10-digits still it is getting masked.
For a CreditCardNo, the range is 12-19 digits. The reason is the space(before and after the digits) which is taken that extra 11th and12 character i think.
The regex in use is
“(?<=(?<![d-])(?=(?:-?[d*s]){12,19}(?![d-*s]))[d-*s])[d*](?!(?:-?[d*s]){0,3}(?![d-*s]))”
I tried below code with above regex –. Expected is that all the scenarios along with the one which is asked in question should work as it is. They can be tested using the URL – https://dotnetfiddle.net/Gopzoz. Thanks
public static string MaskNewAccNo(this string value)
{
var a = Regex.Replace(value, @"(?<=(?<![d-*])(?=(?:-?[d*]){8,9}(?![d-*]))[d-*]*)[d*](?!(?:-?[d*]){0,3}(?![d-*]))", "x");
return a;
}