You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The phone number "+1 800 723 3456" parses fine as expected. Then the formatted output is "+1 800-723-3456", but this fails to parse. Though "+1-800-723-3456" successfully parses.
I'd suggest being more forgiving in PhoneNumber::from_str and just entirely ignoring spaces and hyphens, and potentially other characters. At the very least, make it so PhoneNumber::from_str can successfully parse its own formatted output.
Example code:
#[test]
fn test() {
use phonenumber::{Mode, PhoneNumber};
let original_phone_number_string = String::from("+1 800 723 3456");
println!("original_phone_number_string: {:?}", original_phone_number_string);
let parsed_phone_number = PhoneNumber::from_str(&original_phone_number_string).unwrap();
println!("parsed_phone_number: {:?}", parsed_phone_number);
let formatted_phone_number_string = parsed_phone_number.format().mode(Mode::International).to_string();
println!("formatted_phone_number_string: {:?}", formatted_phone_number_string);
// This call fails, and we panic on the unwrap for dramatic purposes.
let reparsed_phone_number = PhoneNumber::from_str(&formatted_phone_number_string).unwrap();
println!("reparsed_phone_number: {:?}", reparsed_phone_number);
}
Is there some documentation somewhere indicating what formats are accepted by PhoneNumber::from_str? I poked around the google libphonenumber repo a bit but didn't see anything obvious either.
The text was updated successfully, but these errors were encountered:
The phone number "+1 800 723 3456" parses fine as expected. Then the formatted output is "+1 800-723-3456", but this fails to parse. Though "+1-800-723-3456" successfully parses.
I'd suggest being more forgiving in PhoneNumber::from_str and just entirely ignoring spaces and hyphens, and potentially other characters. At the very least, make it so PhoneNumber::from_str can successfully parse its own formatted output.
Example code:
Is there some documentation somewhere indicating what formats are accepted by PhoneNumber::from_str? I poked around the google libphonenumber repo a bit but didn't see anything obvious either.
The text was updated successfully, but these errors were encountered: