Crate phonelib

Crate phonelib 

Source
Expand description

§Phonelib

A comprehensive Rust library for handling phone numbers.

§Features

  • Validation - Check if phone numbers are valid
  • Country Detection - Extract country information from phone numbers
  • Normalization - Clean and standardize phone number formats
  • Multiple Format Support - E.164, International, National, RFC3966
  • Type Detection - Identify mobile, landline, toll-free, premium numbers
  • Text Extraction - Parse phone numbers from free-form text
  • Comparison/Equality - Compare numbers regardless of format
  • Batch Processing - Process multiple numbers efficiently

§Quick Start

use phonelib::*;

// Basic validation
let is_valid = is_valid_phone_number("+12025550173".to_string());
assert!(is_valid);

// Normalize a number
let normalized = normalize_phone_number("12025550173".to_string());
assert_eq!(normalized, Some("+12025550173".to_string()));

// Extract phone numbers from text
let text = "Call me at +12025550173 or +442079460958";
let numbers = extract_phone_numbers_from_text(text);
assert_eq!(numbers.len(), 2);

// Compare phone numbers (different formats, same number)
let num1 = PhoneNumber::parse("+12025550173").unwrap();
let num2 = PhoneNumber::parse("12025550173").unwrap();
assert_eq!(num1, num2);

Structs§

ExtractedPhoneNumber
Result of extracting a phone number from text
PhoneNumber
A parsed and validated phone number with equality comparison
PhoneNumberAnalysis
Detailed analysis result for a phone number
PhoneNumberSet
A collection of phone numbers that can be compared and deduplicated

Enums§

PhoneFormat
Phone number format options
PhoneNumberType
Phone number types

Functions§

analyze_phone_numbers_batch
Comprehensive batch analysis of phone numbers
are_phone_numbers_equal
Check if two phone numbers are equivalent (same number, different formats)
count_phone_numbers_in_text
Count how many phone numbers are in the text
detect_phone_number_type
Detect the type of a phone number (mobile, landline, toll-free, etc.)
detect_phone_number_types_batch
Detect phone number types for multiple numbers at once
extract_countries_batch
Extract countries for multiple phone numbers at once
extract_country
Extracts country information from a phone number.
extract_phone_numbers_from_text
Extract all phone numbers from free-form text
extract_phone_numbers_with_country_hint
Extract phone numbers from text with a country hint
extract_valid_phone_numbers_from_text
Extract only valid phone numbers from text
format_phone_number
Format a phone number according to the specified format
generate_random_phone_number
Generate a random valid phone number for a specific country
generate_random_phone_numbers
Generate multiple random valid phone numbers for a specific country
group_equivalent_phone_numbers
Compare multiple phone numbers and group them by equivalence
guess_country_from_number
Get the most likely country for a phone number based on patterns
is_landline_number
Check if a phone number is a landline number
is_mobile_number
Check if a phone number is a mobile number
is_potentially_valid_phone_number
Check if a phone number is potentially valid but incorrectly formatted
is_toll_free_number
Check if a phone number is a toll-free number
is_valid_phone_number
Validates whether a phone number is valid.
normalize_phone_number
Normalizes a phone number to E.164 format.
normalize_phone_number_in_place
Normalizes a phone number in place to E.164 format.
normalize_phone_numbers_batch
Normalize multiple phone numbers at once
redact_phone_numbers
Redact (mask) phone numbers in text for privacy
replace_phone_numbers_in_text
Replace phone numbers in text with a placeholder or transformed version
suggest_phone_number_corrections
Suggest corrections for an invalid phone number
validate_phone_numbers_batch
Validate multiple phone numbers at once