You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Open-source library for generating valid phone numbers in the E.164 format based on upgraded metadata from libphonenumber
Why not just use the libphonenumber?
There are several reasons for this:
The libphonenumber doesn't provide an API for generating valid phone numbers by default. Using getExampleNumber, you can only get one example for each type of phone number in each region.
Unnecessary duplication of patterns or parts of patterns in regions with the same country code. For example, the JE national part pattern for personal phone numbers (701511\d{4}) is a subset of the GB national part pattern for personal phone numbers (70\d{8}) in libphonenumber 8.13.5
Ok, fine, how to use it?
First, find out which version is needed by looking at VERSIONS.md.
‼️The version of libphonenumber in your project SHOULD BE EQUAL to the version of libphonenumber in the raf library. Otherwise there is no guarantee that the generated phones will be correctly parsed by libphonenumber. Be very careful here! ‼️
Then, add the following dependency:
// rafVersion is the version that you found in the previous step"io.github.mr-tolmach"%%"raf-generators"% rafVersion
Finally, use it in your code:
importio.github.mr_tolmach.generators.E164Generatorsimportio.github.mr_tolmach.metadata.model.Regionsimportio.github.mr_tolmach.metadata.model.PhoneNumberTypes// for scalatest + scalacheck property-based testing
forAll(E164Generators.phoneNumberGen(Regions.AW))(check)
// to generate valid phone numbers for the AC region with any type of phone numberE164Generators.phoneNumberGen(Regions.AC).sample
// to generate valid fixed-line phone numbers for the US regionE164Generators.phoneNumberGen(Regions.US, PhoneNumberTypes.FixedLine).sample
About
Open-source library for generating valid phone numbers in the E.164 format based on upgraded metadata from libphonenumber