https://github.com/javadev/phone-utils
A convenient phone library helping to work with phone numbers.
https://github.com/javadev/phone-utils
Last synced: 3 months ago
JSON representation
A convenient phone library helping to work with phone numbers.
- Host: GitHub
- URL: https://github.com/javadev/phone-utils
- Owner: javadev
- License: mit
- Created: 2019-02-06T00:51:54.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-11-23T01:22:36.000Z (7 months ago)
- Last Synced: 2025-01-31T08:32:54.663Z (5 months ago)
- Language: Java
- Size: 32.2 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# phone-utils
A convenient phone library helping to work with phone numbers.[](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.github.javadev%22%20AND%20a%3A%22phone-utils%22)
[ ](https://github.com/javadev/phone-utils/blob/master/LICENSE)
[](https://github.com/javadev/phone-utils/actions/workflows/maven.yml)
[](https://codecov.io/github/javadev/phone-utils)Requirements
============Java 1.8 and later.
## Installation
Include the following in your `pom.xml` for Maven:
```
com.github.javadev
phone-utils
1.0
...```
Gradle:
```groovy
compile 'com.github.javadev:phone-utils:1.0'
```## Definitions
Definitions of vocabulary used in project
* Country code - Integer. Examples: 380, 47, 46, etc
* National number - String. (+47)45037118, (+380)985777268
* Full phone number: + Country code and national number
* Valid phone number: means that Google library says that this is real number according to Telecom rules
* Possible number: semantically incorrect, but syntactically correct numbers.## Examples
### Check if number is valid
```
$ isValidPhoneNumber("+47", "45 45 45 45") => true
$ isValidPhoneNumber("+47", "85 45 45 45") => false
```### Check if possible number
```
$ isPossibleFullPhoneNumber("+4736985214") => true
$ isPossibleFullPhoneNumber("+473698521fdsd4") => false
```### Normalize number
```
$ normalizePhoneNumber("+1 (650) - 713 (9923)") => +16507139923
```## Check if number has given country code (for example: Norway)
```
$ hasCountryCode(47, "+4736985214") => true
$ hasCountryCode(46, "+4736985214") => false
$ hasCountryCode(47, "+478587845454545") => false (not possible number)
```## Check valid norwegian number
```
$ isValidNorwegianPhoneNumber("45037118") => true
$ isValidNorwegianPhoneNumber("906 (30) 185") => true
$ isValidNorwegianPhoneNumber("+47 906 (30) 185") => true
$ isValidNorwegianPhoneNumber("+4790630185") => true
$ isValidNorwegianPhoneNumber("800185") => false
$ isValidNorwegianPhoneNumber("80630185") => false
$ isValidNorwegianPhoneNumber("+47 80630185") => false
```## Generate valid full norwegian number
```
$ generateFullNorwegianPhoneNumber("45037118") => +4745037118
$ generateFullNorwegianPhoneNumber("906 (30) 185") => +4790630185
$ generateFullNorwegianPhoneNumber("+47 906 (30) 185") => +4790630185
```