#numbers #phone #parser #formatter

phonenumber

Library for parsing, formatting and validating international phone numbers

13 releases

0.3.6+8.13.36 Jul 9, 2024
0.3.4+8.13.34 Apr 11, 2024
0.3.3+8.13.9 Sep 19, 2023
0.3.2+8.13.9 Mar 31, 2023
0.1.0+8.7.0 Jul 31, 2017

#41 in Value formatting

Download history 30206/week @ 2024-08-02 31013/week @ 2024-08-09 28254/week @ 2024-08-16 27761/week @ 2024-08-23 35409/week @ 2024-08-30 45486/week @ 2024-09-06 40612/week @ 2024-09-13 47431/week @ 2024-09-20 46881/week @ 2024-09-27 44185/week @ 2024-10-04 39307/week @ 2024-10-11 51014/week @ 2024-10-18 46496/week @ 2024-10-25 49288/week @ 2024-11-01 50064/week @ 2024-11-08 55405/week @ 2024-11-15

211,050 downloads per month
Used in 37 crates (25 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

~7.5MB
~147K SLoC