Skip to content

Commit

Permalink
Fixing bugs python lib
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-logan committed Aug 23, 2023
1 parent 03cd992 commit f500633
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 26 deletions.
22 changes: 22 additions & 0 deletions pythonVersion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ If you want to help me, you can buy me a coffee (:
pip install multiform-validator
```

# Avaliable for while

- **cnpjValidator**: CNPJ validation.
- **cpfValidator**: CPF validation.
- **getOnlyEmail**: Extracts only the email or emails address from a string.
- **identifyFlagCard**: Identifies the flag of a credit card.
- **isCreditCardValid**: Credit card validation.
- **isEmail**: Email address validation format.
- **passwordStrengthTester**: Password strength test.
- **validateBRPhoneNumber**: Brazilian phone number validation.

from multiform_validator import (
cnpjIsValid,
cpfIsValid,
getOnlyEmail,
identifyFlagCard,
isCreditCardValid,
isEmail,
passwordStrengthTester,
validateBRPhoneNumber
)

# Data Validator

This package contains various modules for validating different types of data. Below are the available validation modules:
Expand Down
22 changes: 21 additions & 1 deletion pythonVersion/src/multiform_validator.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: multiform-validator
Version: 0.0.3
Version: 0.0.5
Summary: A small example package
Author: Gabriel Logan
Project-URL: Homepage, https://github.com/gabriel-logan/multiform-validator/tree/main/pythonVersion
Expand Down Expand Up @@ -40,6 +40,26 @@ If you want to help me, you can buy me a coffee (:
pip install multiform-validator
```

# Avaliable for while

- **cnpjValidator**: CNPJ validation.
- **cpfValidator**: CPF validation.
- **getOnlyEmail**: Extracts only the email or emails address from a string.
- **identifyFlagCard**: Identifies the flag of a credit card.
- **isCreditCardValid**: Credit card validation.
- **isEmail**: Email address validation format.
- **passwordStrengthTester**: Password strength test.
- **validateBRPhoneNumber**: Brazilian phone number validation.

from .cpfValidator import cpfValidator as
from .cnpjValidator import cnpjValidator as cnpjIsValid
from .getOnlyEmail import getOnlyEmail
from .isEmail import isEmail
from .identifyFlagCard import identifyFlagCard
from .isCreditCardValid import isCreditCardValid
from .passwordStrengthTester import passwordStrengthTester
from .validateBRPhoneNumber import validateBRPhoneNumber

# Data Validator

This package contains various modules for validating different types of data. Below are the available validation modules:
Expand Down
3 changes: 1 addition & 2 deletions pythonVersion/src/multiform_validator/cnpjValidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def calculate_second_verifier(cnpj_base, first_verifier):

default_error_msg = ['CNPJ invalid', 'CNPJ must have 14 numerical digits', 'CNPJ is not valid', 'Unknown error']

def cnpjValidator(cnpj: str, errorMsg: list[str, str or None]=default_error_msg) -> object[bool, str or None]:
def cnpjValidator(cnpj: str, errorMsg: list[str, str or None]=default_error_msg) -> dict[bool, str or None]:
if not isinstance(cnpj, str):
raise TypeError('The input should be a string.')

Expand Down Expand Up @@ -59,4 +59,3 @@ def get_error_message(index):
'isValid': False,
'errorMsg': get_error_message(3), # 'Unknown error'
}

2 changes: 0 additions & 2 deletions pythonVersion/src/multiform_validator/cpfValidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,3 @@ def getErrorMessage(index):
"isValid": False,
"errorMsg": getErrorMessage(3),
}


22 changes: 12 additions & 10 deletions pythonVersion/src/multiform_validator/identifyFlagCard.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import re

def identifyFlagCard(cardNumber: str):
if not isinstance(cardNumber, str):
raise TypeError('The input should be a string.')

bandeiras = [
{'name': 'Visa', 'interval': '^4'},
{'name': 'Mastercard', 'interval': '^5[1-5]'},
{'name': 'American Express', 'interval': '^3[47]'},
{'name': 'Discover', 'interval': '^6(?:011|5)'},
{'name': 'JCB', 'interval': '^(?:2131|1800|35\d{3})'},
{'name': 'Diners Club', 'interval': '^3(?:0[0-5]|[68])'},
{'name': 'Maestro', 'interval': '^(?:5[0678]\d\d|6304|6390|67\d\d)'},
{'name': 'UnionPay', 'interval': '^(62|88)'},
{'name': 'Elo', 'interval': '^63[789]'},
{'name': 'Hipercard', 'interval': '^(3841|60)'},
{'name': 'Visa', 'interval': re.compile('^4')},
{'name': 'Mastercard', 'interval': re.compile('^5[1-5]')},
{'name': 'American Express', 'interval': re.compile('^3[47]')},
{'name': 'Discover', 'interval': re.compile('^6(?:011|5)')},
{'name': 'JCB', 'interval': re.compile('^(?:2131|1800|35\d{3})')},
{'name': 'Diners Club', 'interval': re.compile('^3(?:0[0-5]|[68])')},
{'name': 'Maestro', 'interval': re.compile('^(?:5[0678]\d\d|6304|6390|67\d\d)')},
{'name': 'UnionPay', 'interval': re.compile('^(62|88)')},
{'name': 'Elo', 'interval': re.compile('^63[789]')},
{'name': 'Hipercard', 'interval': re.compile('^(3841|60)')},
]

def find_interval(band):
Expand Down
25 changes: 15 additions & 10 deletions pythonVersion/src/multiform_validator/isCreditCardValid.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
def isCreditCardValid(cardNumber: str):
def isCreditCardValid(cardNumber: str) -> bool:
if not isinstance(cardNumber, str):
raise TypeError('The input should be a string.')

digits = list(map(int, filter(str.isdigit, cardNumber)))
tamanho_do_digito = len(digits)
sum_value = 0
is_even = False
# Remove espaços em branco e verifica se todos os caracteres são dígitos
cardNumber = cardNumber.replace(" ", "")
if not cardNumber.isdigit():
return False

for i in range(tamanho_do_digito - 1, -1, -1):
digits = list(map(int, cardNumber))
tamanhoDoDigito = len(digits)
totalSum = 0
isEven = False

for i in range(tamanhoDoDigito - 1, -1, -1):
digit = digits[i]
if is_even:
if isEven:
digit *= 2
if digit > 9:
digit -= 9
sum_value += digit
is_even = not is_even
totalSum += digit
isEven = not isEven

return sum_value % 10 == 0
return totalSum % 10 == 0
1 change: 0 additions & 1 deletion pythonVersion/src/multiform_validator/isEmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ def isEmail(email: str) -> bool:
return True
except Exception:
return False

0 comments on commit f500633

Please sign in to comment.