/// <summary> /// Check email or mobile id /// 检查Email或手机编号 /// </summary> /// <param name="id">Email or mobile</param> /// <param name="region">Region</param> /// <param name="isEmail">Is email</param> /// <returns>Result, null means failure</returns> public static string?CheckId(string id, string region, out bool isEmail) { if (string.IsNullOrEmpty(id)) { isEmail = false; return(null); } isEmail = id.Contains('@'); if (isEmail) { // Try parse if (MailboxAddress.TryParse(id, out var emailAddress)) { return(emailAddress.Address); } } else { // Try parse and format var phone = AddressRegion.CreatePhone(id, region); if (phone != null) { return(phone.ToInternationalFormat()); } } return(null); }
public void Countries_CreatePhone_BulkTests(string phoneNumber, string region, string formatedNumber, bool isMobile) { // Arrange & act var phone = AddressRegion.CreatePhone(phoneNumber); Assert.AreEqual(region, phone?.Region); Assert.AreEqual(formatedNumber, phone?.PhoneNumber); Assert.AreEqual(isMobile, phone?.IsMobile); }
public void CountryPhone_ToInternationalFormat_Tests() { // Arrange var phone = AddressRegion.CreatePhone("0210722065", "NZ"); // Act 1 var result1 = phone?.ToInternationalFormat(); // Assert 1 Assert.AreEqual("+64210722065", result1); // Act 2 var result2 = phone?.ToInternationalFormat("00"); // Assert 2 Assert.AreEqual("0064210722065", result2); }