Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/whisperfish/rust-phonenumber
Library for parsing, formatting and validating international phone numbers.
https://github.com/whisperfish/rust-phonenumber
formatter parser phone-number rust rust-library validator
Last synced: 3 days ago
JSON representation
Library for parsing, formatting and validating international phone numbers.
- Host: GitHub
- URL: https://github.com/whisperfish/rust-phonenumber
- Owner: whisperfish
- License: apache-2.0
- Created: 2017-06-29T10:30:17.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2025-01-11T12:53:33.000Z (20 days ago)
- Last Synced: 2025-01-22T01:52:32.298Z (10 days ago)
- Topics: formatter, parser, phone-number, rust, rust-library, validator
- Language: Rust
- Homepage:
- Size: 4.56 MB
- Stars: 166
- Watchers: 10
- Forks: 58
- Open Issues: 27
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# phonenumber
![CI Build](https://github.com/whisperfish/rust-phonenumber/workflows/Build/badge.svg)
[![Crates.io](https://img.shields.io/crates/v/phonenumber.svg)](https://crates.io/crates/phonenumber)
[![phonenumber](https://docs.rs/phonenumber/badge.svg)](https://docs.rs/phonenumber)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)Rust version of [libphonenumber](https://github.com/googlei18n/libphonenumber).
We currently require 1.58.0 as minimum supported Rust version (MSRV).## Usage
Add this to your `Cargo.toml`:
```toml
[dependencies]
phonenumber = "0.3"
```
## ExampleThe following example parses, validates and formats the given phone number.
```rust,no_run
use phonenumber::Mode;
use std::env;fn main() {
let mut args = env::args().skip(1).collect::>();if args.len() < 1 {
panic!("not enough arguments");
}let number = args.pop().unwrap();
let country = args.pop().map(|c| c.parse().unwrap());let number = phonenumber::parse(country, number).unwrap();
let valid = phonenumber::is_valid(&number);if valid {
println!("\x1b[32m{:#?}\x1b[0m", number);
println!();
println!("International: {}", number.format().mode(Mode::International));
println!(" National: {}", number.format().mode(Mode::National));
println!(" RFC3966: {}", number.format().mode(Mode::Rfc3966));
println!(" E.164: {}", number.format().mode(Mode::E164));
}
else {
println!("\x1b[31m{:#?}\x1b[0m", number);
}
}
```