using System.Text.Json.Serialization;
using static PhoneNumbers.PhoneNumberUtil;
public static void Main()
var phoneValidator = new PhoneValidator();
var (isSuccess, _, countryCode) = phoneValidator.Validate("+85244106298");
Console.WriteLine(isSuccess);
Console.WriteLine(countryCode);
public class PhoneValidator
private readonly PhoneNumberUtil _phoneNumberUtil = PhoneNumberUtil.GetInstance();
public (bool isSuccess, string interPhoneNumber, string countryCode) Validate(string interPhoneNumber)
var parsedPhoneNumber = this._phoneNumberUtil.Parse(interPhoneNumber, null);
if (!this._phoneNumberUtil.IsValidNumber(parsedPhoneNumber))
return (false, default, default);
return (true, this._phoneNumberUtil.Format(parsedPhoneNumber, PhoneNumberFormat.E164),
_phoneNumberUtil.GetRegionCodeForNumber(parsedPhoneNumber));
return (false, default, default);
public (bool isSuccess, string interPhoneNumber, string countryCode) Validate(
string countryCallingCode, string phoneNumber)
return this.Validate($"{countryCallingCode}{phoneNumber}");