-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03cd992
commit f500633
Showing
7 changed files
with
71 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,5 +90,3 @@ def getErrorMessage(index): | |
"isValid": False, | ||
"errorMsg": getErrorMessage(3), | ||
} | ||
|
||
|
22 changes: 12 additions & 10 deletions
22
pythonVersion/src/multiform_validator/identifyFlagCard.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 15 additions & 10 deletions
25
pythonVersion/src/multiform_validator/isCreditCardValid.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,3 @@ def isEmail(email: str) -> bool: | |
return True | ||
except Exception: | ||
return False | ||
|