Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- `is_valid_phone` aceitava dígitos de outros alfabetos, como `٩` [#807](https://github.com/brazilian-utils/python/issues/807)
- Cálculo do dígito verificador em `is_valid_legal_process` e `generate_legal_process`, que rejeitava números de processo reais e gerava números inválidos [#785](https://github.com/brazilian-utils/python/pull/785)

## [2.5.0] - 2026-06-30
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ Argumentos:

- phone_number (str):
- o número de telefone a ser validado
- apenas dígitos, sem símbolos
- apenas dígitos de 0 a 9, sem símbolos
- sem o código do país
- deve incluir o número de DDD com dois dígitos
- exemplo: '+55 48 9999 9999' deve ser utilizado como '4899999999'
Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ Args:

- phone_number:
- the phone number to be validated
- digits only, no symbols
- ASCII digits (0-9) only, no symbols
- without the country code
- should include the area code (DDD) with two digits
- example: '+55 48 9999 9999' should be used as '4899999999'
Expand Down
10 changes: 5 additions & 5 deletions brutils/phone.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def is_valid(phone_number: str, type: str = None) -> bool:

Args:
phone_number (str): The phone number to validate.
Only digits, without country code.
Only ASCII digits (0-9), without country code.
It should include two digits DDD.
type (str): "mobile" or "landline".
If not specified, checks for one or another.
Expand Down Expand Up @@ -148,14 +148,14 @@ def _is_valid_mobile(phone_number: str) -> bool:

Args:
phone_number (str): The mobile number to validate.
Only digits, without country code.
Only ASCII digits (0-9), without country code.
It should include two digits DDD.

Returns:
bool: True if the phone number is valid. False otherwise.
"""

pattern = re.compile(r"^[1-9][1-9][9]\d{8}$")
pattern = re.compile(r"^[1-9][1-9][9]\d{8}$", re.ASCII)
return (
isinstance(phone_number, str)
and re.match(pattern, phone_number) is not None
Expand All @@ -169,14 +169,14 @@ def _is_valid_landline(phone_number: str) -> bool:

Args:
phone_number (str): The landline number to validate.
Only digits, without country code.
Only ASCII digits (0-9), without country code.
It should include two digits DDD.

Returns:
bool: True if the phone number is valid. False otherwise.
"""

pattern = re.compile(r"^[1-9][1-9][2-5]\d{7}$")
pattern = re.compile(r"^[1-9][1-9][2-5]\d{7}$", re.ASCII)
return (
isinstance(phone_number, str)
and re.match(pattern, phone_number) is not None
Expand Down
19 changes: 19 additions & 0 deletions tests/phone/test_phone.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@


class TestPhone(TestCase):
def test_is_valid(self):
# When the phone number is valid
self.assertIs(is_valid("11994029275"), True)
self.assertIs(is_valid("11994029275", type="mobile"), True)
self.assertIs(is_valid("1938814933"), True)
self.assertIs(is_valid("1938814933", type="landline"), True)

# When the phone number contains non-ASCII digits, returns False
self.assertIs(is_valid("119" + "٩" * 8), False)
self.assertIs(is_valid("119" + "٩" * 8, type="mobile"), False)
self.assertIs(is_valid("113" + "٩" * 7), False)
self.assertIs(is_valid("113" + "٩" * 7, type="landline"), False)
self.assertIs(is_valid("11994029275"), False)

# When the phone number contains superscript digits, returns False
self.assertIs(is_valid("1199402927" + "⁵"), False)
self.assertIs(is_valid("1199402927" + "⁵", type="mobile"), False)
self.assertIs(is_valid("193881493" + "³", type="landline"), False)

def test_remove_symbols_phone(self):
# When the string empty, it returns an empty string
self.assertEqual(remove_symbols_phone(""), "")
Expand Down
Loading