core.bones.phone
¶
Module Contents¶
Classes¶
The PhoneBone class is designed to store validated phone/fax numbers in configurable formats. |
Attributes¶
- core.bones.phone.DEFAULT_REGEX = '^\\+?(\\d{1,3})[-\\s]?(\\d{1,4})[-\\s]?(\\d{1,4})[-\\s]?(\\d{1,9})$'¶
- class core.bones.phone.PhoneBone(*, test=DEFAULT_REGEX, max_length=15, default_country_code=None, **kwargs)¶
Bases:
viur.core.bones.string.StringBone
The PhoneBone class is designed to store validated phone/fax numbers in configurable formats. This class provides a number validation method, ensuring that the given phone/fax number conforms to the required/configured format and structure.
Initializes the PhoneBone with an optional custom regex for phone number validation, a default country code, and a flag to apply the default country code if none is provided.
- Parameters:
test (Optional[Pattern[str]]) – An optional custom regex pattern for phone number validation.
max_length (int) – The maximum length of the phone number. Passed to “StringBone”.
default_country_code (Optional[str]) – The default country code to apply (with leading +) for example “+49”
kwargs (Any) –
If None is provided the PhoneBone will ignore auto prefixing of the country code. :param kwargs: Additional keyword arguments. Passed to “StringBone”. :raises ValueError: If the default country code is not in the correct format for example “+123”.
- type: str = 'str.phone'¶
A string representing the type of the bone, in this case “str.phone”.
- static _extract_digits(value)¶
Extracts and returns only the digits from the given value.
- Parameters:
value (str) – The input string from which to extract digits.
- Returns:
A string containing only the digits from the input value.
- Return type:
str
- isInvalid(value)¶
Checks if the provided phone number is valid or not.
- Parameters:
value (str) – The phone number to be validated.
- Returns:
An error message if the phone number is invalid or None if it is valid.
- Return type:
Optional[str]
The method checks if the provided phone number is valid according to the following criteria: 1. The phone number must not be empty. 2. The phone number must match the provided or default phone number format. 3. The phone number cannot exceed 15 digits, or the specified maximum length if provided (digits only).
- singleValueFromClient(value, skel, bone_name, client_data)¶
Processes a single value from the client, applying the default country code if necessary and validating the phone number.
- Parameters:
value (str) – The phone number provided by the client.
skel (Any) – Skeleton data (not used in this method).
bone_name (str) – The name of the bone (not used in this method).
client_data (Any) – Additional client data (not used in this method).
- Returns:
A tuple containing the processed phone number and an optional list of errors.
- Return type:
Tuple[Optional[str], Optional[List[viur.core.bones.base.ReadFromClientError]]]
- structure()¶
Returns the structure of the PhoneBone, including the test regex pattern.
- Returns:
A dictionary representing the structure of the PhoneBone.
- Return type:
Dict[str, Any]