Created
September 13, 2021 09:44
-
-
Save DineshSolanki/8e76167e93f7c0a50b415778ee83f9b6 to your computer and use it in GitHub Desktop.
Get country mobile number mask using libphone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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