Skip to main content

ValidatePhoneNumber

Trait ValidatePhoneNumber 

Source
pub trait ValidatePhoneNumber {
    // Required method
    fn as_phone_number_string(&self) -> Cow<'_, str>;

    // Provided method
    fn validate_phone_number(&self, country_id_str: Option<&str>) -> bool { ... }
}
Expand description

A trait for types that can be validated as a phone number.

Implementors must provide a way to get the phone number as a string via the as_phone_number_string method.

Required Methods§

Source

fn as_phone_number_string(&self) -> Cow<'_, str>

Returns the phone number as a Cow<str>.

Provided Methods§

Source

fn validate_phone_number(&self, country_id_str: Option<&str>) -> bool

Validates the phone number string using the phonenumber crate.

§Arguments
  • country_id_str: An optional phonenumber::country::Id as a string.
§Returns

true if the phone number is valid for the given country (or if inferable and valid), false otherwise.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: AsRef<str>> ValidatePhoneNumber for T

Implements ValidatePhoneNumber for any type that can be converted to a string slice (AsRef<str>).