Skip to content

Library for parsing, formatting and validating international phone numbers.

License

Notifications You must be signed in to change notification settings

virtualritz/rust-phonenumber

This branch is 26 commits behind whisperfish/rust-phonenumber:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

570f807 · May 13, 2024
May 7, 2024
May 13, 2024
Dec 14, 2023
Dec 14, 2023
Apr 23, 2024
Jul 6, 2017
Jul 12, 2017
May 13, 2024
Jul 6, 2017
Dec 14, 2023
Dec 14, 2023

Repository files navigation

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

About

Library for parsing, formatting and validating international phone numbers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 99.7%
  • Shell 0.3%