-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidate Phone Numbe Structure
More file actions
29 lines (23 loc) · 1.49 KB
/
Validate Phone Numbe Structure
File metadata and controls
29 lines (23 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Conheça mais sobre o Regex: https://docs.python.org/pt-br/3.8/howto/regex.html
# Conheça mais sobre o 're' do python: https://docs.python.org/pt-br/3/library/re.html
# Módulo 're' que fornece operações com expressões regulares.
# Import this
import re
# Criar uma função chamada 'validate_numero_telefone' que aceite um argumento 'phone_number':
def validate_numero_telefone(phone_number):
# Definir um padrão de expressão regular (regex) para validar números de telefone no formato (XX) 9XXXX-XXXX:
pattern = r"\([0-9]{2}\) 9[0-9]{4}-[0-9]{4}"
# A função 're.match()' para verifica se o padrão definido corresponde ao número de telefone fornecido.
# O 're.match()' retorna um objeto 'match' se houver correspondência no início da string, caso contrário, retorna 'None'.
if re.match(pattern, phone_number):
# TODO: Agora crie um return, para retornar que o número de telefone é válido:
return 'Número de telefone válido.'
# Criar um else e return, caso não o número de telefone seja inválido:
else:
return 'Número de telefone inválido.'
# Solicitar ao usuário que insira um número de telefone e armazena o valor fornecido na variável 'phone_number'.
phone_number = input()
# Chamar a função 'validate_numero_telefone()' com o número de telefone fornecido como argumento e armazene o resultado retornado na variável 'result'.
result = validate_numero_telefone(phone_number)
# Imprimir o resultado:
print(result)