Python Doc

Back to home

pypi versionLicense: MITpypi downloads

Installation

Install the package using pip:

pip install multiform-validator
from multiform_validator import (
	cnpjIsValid,
	cpfIsValid,
	getOnlyEmail,
	identifyFlagCard,
	isCreditCardValid,
	isEmail,
	passwordStrengthTester,
	validateBRPhoneNumber,
	isValidImage
)

Methods

isEmail:

print("Is email", isEmail("foo@bar.com")) # True

print("Is not email", isEmail("foo@bar")) # False

getOnlyEmail:

print("Get only email", getOnlyEmail("awdawd wadawd wda awd jhony@gmail.com awdawdawd"))
# jhony@gmail.com

print("Multiple emails", getOnlyEmail("dawd foo@bar.com adwda wdaw da @dadwa odiw jon@foob.com", True))
# ['foo@bar.com', 'jon@foob.com']

print("Multiple and cleanDomains", getOnlyEmail(
    """
    awawdi wadwad iu awd foor@bar.comAOWDowad wdaoiwdo @OIDOim2o2OID@AD@D@@@@D odi2 2oid2odi2D
    aodo2d@doaiaod jhon@bar.com.brADW
    """, True, True
)) # ['foor@bar.com', 'jhon@bar.com.br']

print("Multiple, clean and repeat emails", getOnlyEmail(
    """
    awawdi wadwad iu awd u awd foor@bar.comAOWDowad wda u
    2d@doaiaod jhon@bar.com.brADW
     awd foor@bar.comAOWDowad wda
    """, True, True, True
)) # ['foor@bar.com', 'jhon@bar.com.br', 'foor@bar.com']

# Each parameter can be passed as false individually, the default for all is false

identifyFlagCard:

print("Identify flag card", identifyFlagCard("5117 2161 1334 8362")) # Mastercard

passwordStrengthTester:

print("Password strength", passwordStrengthTester("aA1!asd@qd2asd")) # Very Strong

cpfIsValid:

print("Is CPF valid", cpfIsValid("123.456.789-02")['isValid']) # False

print("Is CPF valid", cpfIsValid("123.456.789-09"))
# {'isValid': False, 'errorMsg': 'CNPJ is not valid'}

cnpjIsValid:

print("Is CNPJ valid", cnpjIsValid("12.345.678/0001-09"))
# { 'isValid': False, 'errorMsg': 'CNPJ is not valid' }

isCreditCardValid:

print("Is credit card valid", isCreditCardValid("5117 2161 1334 8362")) # True

isCreditCardValid:

print("Is credit card valid", isCreditCardValid("5117 2161 1334 8362")) # True

validateBRPhoneNumber:

print("Validate BR phone number", validateBRPhoneNumber("(11) 91234-5678"))
# { 'isValid': True, 'errorMsg': None }

isValidImage:

import os
from pathlib import Path

from multiform_validator import isValidImage

# Resolve the file path
file_path = Path.cwd() / 'static' / 'uploads'
retrieved_file = file_path / filename

# Read the first 4 bytes of the file
with open(retrieved_file, 'rb') as f:
    file_buffer = f.read(4)

print(isValidImage(file_buffer)) # True or False

Functions signature

All params with default values are optional.

def isEmail(email: str) -> bool:
    pass

def getOnlyEmail(text: str, multiple=False, clean_domain=False, repeat_email=False) -> str:
    pass

def passwordStrengthTester(password: str) -> str:
    pass

defaultErrorMsgCPF = [
  'CPF invalid',
  'CPF must have 11 numerical digits',
  'CPF is not valid',
  'Unknown error',
]
def cpfIsValid(cpf: str, errorMsg=defaultErrorMsgCPF) -> Dict[str, Union[bool, str, None]]:
    pass

default_error_msgCNPJ = [
   'CNPJ invalid',
   'CNPJ must have 14 numerical digits',
   'CNPJ is not valid',
   'Unknown error'
]
def cnpjIsValid(cnpj: str, errorMsg=default_error_msgCNPJ) -> Dict[str, Union[bool, str, None]]:
    pass

def isCreditCardValid(cardNumber: str) -> bool:
    pass

def identifyFlagCard(cardNumber: str) -> str:
    pass

default_error_msg = ['Invalid value passed', 'Invalid phone number', 'Unknown error']
def validateBRPhoneNumber(phoneNumber: str, errorMsg=default_error_msg) -> Dict[str, Union[bool, str, None]]:
    pass

def isValidImage(file_buffer: bytes) -> bool:
	pass