phonenumber-fixed

Crates.iophonenumber-fixed
lib.rsphonenumber-fixed
version0.3.1+8.12.9-1
sourcesrc
created_at2023-01-26 16:33:53.685987
updated_at2023-01-26 16:33:53.685987
descriptionLibrary for parsing, formatting and validating international phone numbers.
homepage
repositoryhttps://github.com/1aim/rust-phonenumber
max_upload_size
id768673
size13,921,229
Shawn (NOBLES5E)

documentation

README

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;
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);
	}
}
Commit count: 132

cargo fmt