#number #parser #formatter #phonenumber #phone

phonenumber

Library for parsing, formatting and validating international phone numbers

4 releases

0.2.3+8.10.6 Mar 6, 2019
0.2.1+8.9.0 Jul 2, 2018
0.2.0+8.9.0 Mar 5, 2018
0.1.0+8.7.0 Jul 31, 2017

#13 in Value formatting

Download history 44/week @ 2018-11-21 92/week @ 2018-11-28 102/week @ 2018-12-05 95/week @ 2018-12-12 89/week @ 2018-12-19 72/week @ 2018-12-26 85/week @ 2019-01-02 94/week @ 2019-01-09 65/week @ 2019-01-16 80/week @ 2019-01-23 59/week @ 2019-01-30 106/week @ 2019-02-06 132/week @ 2019-02-13 104/week @ 2019-02-20 110/week @ 2019-02-27

400 downloads per month
Used in 5 crates (3 directly)

Apache-2.0

2.5MB
3.5K SLoC

phonenumber Crates.io phonenumber License Build Status

Rust version of libphonenumber by Google.

Usage

Add this to your Cargo.toml:

[dependencies]
phonenumber = "0.1"

Example

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

extern crate phonenumber;
use phonenumber::Mode;

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
~209K SLoC

  • build build.rs