#numbers-parser #parser #phone #formatter #numbers

phonenumber

Library for parsing, formatting and validating international phone numbers

14 releases

0.3.7+8.13.52 Jan 11, 2025
0.3.6+8.13.36 Jul 9, 2024
0.3.5+8.13.36 May 13, 2024
0.3.3+8.13.9 Sep 19, 2023
0.1.0+8.7.0 Jul 31, 2017

#41 in Value formatting

Download history 51339/week @ 2024-12-05 50472/week @ 2024-12-12 29492/week @ 2024-12-19 13735/week @ 2024-12-26 40599/week @ 2025-01-02 53675/week @ 2025-01-09 48330/week @ 2025-01-16 51758/week @ 2025-01-23 54204/week @ 2025-01-30 57721/week @ 2025-02-06 47345/week @ 2025-02-13 53830/week @ 2025-02-20 59377/week @ 2025-02-27 63590/week @ 2025-03-06 65811/week @ 2025-03-13 47570/week @ 2025-03-20

246,354 downloads per month
Used in 43 crates (30 directly)

Apache-2.0

13MB
3.5K SLoC

phonenumber

CI Build Crates.io phonenumber License

Rust version of libphonenumber. We currently require 1.58.0 as minimum supported Rust version (MSRV).

Usage

Add this to your Cargo.toml:

[dependencies]
phonenumber = "0.3"

Example

The following example parses, validates and formats the given phone number.

use phonenumber::Mode;
use std::env;

fn main() {
	let mut args = env::args().skip(1).collect::<Vec<_>>();

	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);
	}
}

Dependencies

~5–6.5MB
~122K SLoC