NBPhoneNumberUtil.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // NBPhoneNumberUtil.h
  3. // libPhoneNumber
  4. //
  5. // Created by tabby on 2015. 2. 8..
  6. // Copyright (c) 2015년 ohtalk.me. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "NBPhoneNumberDefines.h"
  10. @class NBPhoneMetaData, NBPhoneNumber;
  11. @interface NBPhoneNumberUtil : NSObject
  12. + (NBPhoneNumberUtil *)sharedInstance;
  13. @property(nonatomic, strong, readonly) NSDictionary *DIGIT_MAPPINGS;
  14. // regular expressions
  15. - (NSArray *)matchesByRegex:(NSString *)sourceString regex:(NSString *)pattern;
  16. - (NSArray *)matchedStringByRegex:(NSString *)sourceString regex:(NSString *)pattern;
  17. - (NSString *)replaceStringByRegex:(NSString *)sourceString
  18. regex:(NSString *)pattern
  19. withTemplate:(NSString *)templateString;
  20. - (int)stringPositionByRegex:(NSString *)sourceString regex:(NSString *)pattern;
  21. // libPhoneNumber Util functions
  22. - (NSString *)convertAlphaCharactersInNumber:(NSString *)number;
  23. - (NSString *)normalize:(NSString *)phoneNumber;
  24. - (NSString *)normalizeDigitsOnly:(NSString *)number;
  25. - (NSString *)normalizeDiallableCharsOnly:(NSString *)number;
  26. - (BOOL)isNumberGeographical:(NBPhoneNumber *)phoneNumber;
  27. - (NSString *)extractPossibleNumber:(NSString *)phoneNumber;
  28. - (NSNumber *)extractCountryCode:(NSString *)fullNumber nationalNumber:(NSString **)nationalNumber;
  29. #if TARGET_OS_IOS
  30. - (NSString *)countryCodeByCarrier;
  31. #endif
  32. - (NSString *)getNddPrefixForRegion:(NSString *)regionCode stripNonDigits:(BOOL)stripNonDigits;
  33. - (NSString *)getNationalSignificantNumber:(NBPhoneNumber *)phoneNumber;
  34. - (NSArray *)getSupportedRegions;
  35. - (NBEPhoneNumberType)getNumberType:(NBPhoneNumber *)phoneNumber;
  36. - (NSNumber *)getCountryCodeForRegion:(NSString *)regionCode;
  37. - (NSString *)getRegionCodeForCountryCode:(NSNumber *)countryCallingCode;
  38. - (NSArray *)getRegionCodesForCountryCode:(NSNumber *)countryCallingCode;
  39. - (NSString *)getRegionCodeForNumber:(NBPhoneNumber *)phoneNumber;
  40. - (NBPhoneNumber *)getExampleNumber:(NSString *)regionCode error:(NSError **)error;
  41. - (NBPhoneNumber *)getExampleNumberForType:(NSString *)regionCode
  42. type:(NBEPhoneNumberType)type
  43. error:(NSError **)error;
  44. - (NBPhoneNumber *)getExampleNumberForNonGeoEntity:(NSNumber *)countryCallingCode
  45. error:(NSError **)error;
  46. - (BOOL)canBeInternationallyDialled:(NBPhoneNumber *)number error:(NSError **)error;
  47. - (BOOL)truncateTooLongNumber:(NBPhoneNumber *)number;
  48. - (BOOL)isValidNumber:(NBPhoneNumber *)number;
  49. - (BOOL)isViablePhoneNumber:(NSString *)phoneNumber;
  50. - (BOOL)isAlphaNumber:(NSString *)number;
  51. - (BOOL)isValidNumberForRegion:(NBPhoneNumber *)number regionCode:(NSString *)regionCode;
  52. - (BOOL)isNANPACountry:(NSString *)regionCode;
  53. - (BOOL)isLeadingZeroPossible:(NSNumber *)countryCallingCode;
  54. - (NBEValidationResult)isPossibleNumberWithReason:(NBPhoneNumber *)number error:(NSError **)error;
  55. - (BOOL)isPossibleNumber:(NBPhoneNumber *)number;
  56. - (BOOL)isPossibleNumber:(NBPhoneNumber *)number error:(NSError **)error;
  57. - (BOOL)isPossibleNumberString:(NSString *)number
  58. regionDialingFrom:(NSString *)regionDialingFrom
  59. error:(NSError **)error;
  60. - (NBEMatchType)isNumberMatch:(id)firstNumberIn second:(id)secondNumberIn error:(NSError **)error;
  61. - (int)getLengthOfGeographicalAreaCode:(NBPhoneNumber *)phoneNumber error:(NSError **)error;
  62. - (int)getLengthOfNationalDestinationCode:(NBPhoneNumber *)phoneNumber error:(NSError **)error;
  63. - (BOOL)maybeStripNationalPrefixAndCarrierCode:(NSString **)numberStr
  64. metadata:(NBPhoneMetaData *)metadata
  65. carrierCode:(NSString **)carrierCode;
  66. - (NBECountryCodeSource)maybeStripInternationalPrefixAndNormalize:(NSString **)numberStr
  67. possibleIddPrefix:(NSString *)possibleIddPrefix;
  68. - (NSNumber *)maybeExtractCountryCode:(NSString *)number
  69. metadata:(NBPhoneMetaData *)defaultRegionMetadata
  70. nationalNumber:(NSString **)nationalNumber
  71. keepRawInput:(BOOL)keepRawInput
  72. phoneNumber:(NBPhoneNumber **)phoneNumber
  73. error:(NSError **)error;
  74. - (NBPhoneNumber *)parse:(NSString *)numberToParse
  75. defaultRegion:(NSString *)defaultRegion
  76. error:(NSError **)error;
  77. - (NBPhoneNumber *)parseAndKeepRawInput:(NSString *)numberToParse
  78. defaultRegion:(NSString *)defaultRegion
  79. error:(NSError **)error;
  80. - (NBPhoneNumber *)parseWithPhoneCarrierRegion:(NSString *)numberToParse error:(NSError **)error;
  81. - (NSString *)format:(NBPhoneNumber *)phoneNumber
  82. numberFormat:(NBEPhoneNumberFormat)numberFormat
  83. error:(NSError **)error;
  84. - (NSString *)formatByPattern:(NBPhoneNumber *)number
  85. numberFormat:(NBEPhoneNumberFormat)numberFormat
  86. userDefinedFormats:(NSArray *)userDefinedFormats
  87. error:(NSError **)error;
  88. - (NSString *)formatNumberForMobileDialing:(NBPhoneNumber *)number
  89. regionCallingFrom:(NSString *)regionCallingFrom
  90. withFormatting:(BOOL)withFormatting
  91. error:(NSError **)error;
  92. - (NSString *)formatOutOfCountryCallingNumber:(NBPhoneNumber *)number
  93. regionCallingFrom:(NSString *)regionCallingFrom
  94. error:(NSError **)error;
  95. - (NSString *)formatOutOfCountryKeepingAlphaChars:(NBPhoneNumber *)number
  96. regionCallingFrom:(NSString *)regionCallingFrom
  97. error:(NSError **)error;
  98. - (NSString *)formatNationalNumberWithCarrierCode:(NBPhoneNumber *)number
  99. carrierCode:(NSString *)carrierCode
  100. error:(NSError **)error;
  101. - (NSString *)formatInOriginalFormat:(NBPhoneNumber *)number
  102. regionCallingFrom:(NSString *)regionCallingFrom
  103. error:(NSError **)error;
  104. - (NSString *)formatNationalNumberWithPreferredCarrierCode:(NBPhoneNumber *)number
  105. fallbackCarrierCode:(NSString *)fallbackCarrierCode
  106. error:(NSError **)error;
  107. - (BOOL)formattingRuleHasFirstGroupOnly:(NSString *)nationalPrefixFormattingRule;
  108. /**
  109. * Returns the mobile token for the provided country calling code if it has one, otherwise
  110. * returns an empty string. A mobile token is a number inserted before the area code when dialing
  111. * a mobile number from that country from abroad.
  112. *
  113. * @param countryCallingCode the country calling code for which we want the mobile token.
  114. * @return the mobile token, as a string, for the given country calling code.
  115. */
  116. - (NSString *)getCountryMobileTokenFromCountryCode:(NSInteger)countryCallingCode;
  117. @end