Skip to content

helakit.phone

helakit.phone

Sri Lankan phone-number validation.

Typical usage::

import helakit as hk

result = hk.validate_phone("0712345678")
result.normalized   # "+94712345678"
result.data         # PhoneDecoded(carrier="Mobitel", line_type="mobile", local="0712345678")

hk.is_valid_phone("+94762345678")  # True

PhoneDecoded dataclass

PhoneDecoded(carrier: str, line_type: LineType, local: str)

Structured metadata returned in ValidationResult.data["decoded"].

PhoneError

Bases: HelakitError

Raised for unrecoverable phone-related programmer errors.

is_valid_phone

is_valid_phone(value: str) -> bool

Return True if value is a valid Sri Lankan phone number.

Parameters:

Name Type Description Default
value str

The phone number to check (local or international form).

required

Returns:

Type Description
bool

True when valid, False otherwise.

Raises:

Type Description
InvalidInputError

If value is not a string.

validate_phone

validate_phone(value: str) -> ValidationResult

Validate a Sri Lankan phone number.

Parameters:

Name Type Description Default
value str

The phone number in local ("0712345678") or international ("+94712345678") form. Spaces and hyphens are stripped before validation.

required

Returns:

Name Type Description
A ValidationResult

class:~helakit._core.result.ValidationResult. When valid,

ValidationResult

normalized holds the canonical +94XXXXXXXXX form and

ValidationResult

data contains:

ValidationResult
  • "decoded" - a :class:PhoneDecoded with carrier, line_type and local representation.
ValidationResult
  • "carrier" - the network operator name (e.g. "Dialog").
ValidationResult
  • "line_type" - "mobile" or "fixed".
ValidationResult
  • "local" - the local 0XXXXXXXXX representation.

Raises:

Type Description
InvalidInputError

If value is not a string.