Skip to content

Instantly share code, notes, and snippets.

@DineshSolanki
Created September 13, 2021 09:44
Show Gist options
  • Save DineshSolanki/8e76167e93f7c0a50b415778ee83f9b6 to your computer and use it in GitHub Desktop.
Save DineshSolanki/8e76167e93f7c0a50b415778ee83f9b6 to your computer and use it in GitHub Desktop.
Get country mobile number mask using libphone
//https://www.nuget.org/packages/libphonenumber-csharp
public static string GetMobileMask(string regionCode) // "IN"
{
try
{
var exampleNumber = PhoneNumberUtil.GetExampleNumberForType(regionCode, PhoneNumberType.MOBILE);
var formattedNumber = PhoneNumberUtil.FormatNumberForMobileDialing(exampleNumber, regionCode, true)[1..];
var mask = Regex.Replace(formattedNumber, @"\d", "0"); //change 0 to whatever you want, my controls treats 0 as any digit
return mask; //"00000 0000"
}
catch (NullReferenceException e)
{
return "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment