Skip to main content

Multilingual library made for validation, various form fields, such as: email, cpf, cnpj, credit card, and much more.

Project description

Multiform-validator

PyPI version License: MIT PyPI downloads

This package provides Python functions to validate various forms fields.

Documentation: https://multiformvalidator.netlify.app/documentation/py

Feel free to find bugs and report them to me. Your feedback is highly appreciated. Hugs from Gabriel Logan!

If you want to help me, you can buy me a coffee (:

Buy Me A Coffee

Installation

pip install multiform-validator

Data Validator

This package contains various modules for validating different types of data. Below are the available validation modules:

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.
  • isValidImage: Image validation.

Usage

Here is an example of how to use the functions in this package:

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

Usage Example

print("Is email", isEmail("foo@bar.com")) # True
print("Get only email", getOnlyEmail("awdawd wadawd wda awd jhony@gmail.com awdawdawd")) # jhony@gmail.com
print("Password strength", passwordStrengthTester("aA1!asd@qd2asd")) # Strong
print("Is CPF valid", cpfIsValid("123.456.789-02")['isValid']) # False
print("Is CNPJ valid", cnpjIsValid("12.345.678/0001-09")) # { 'isValid': False, 'errorMsg': 'CNPJ is not valid' }
print("Is credit card valid", isCreditCardValid("5117 2161 1334 8362")) # True
print("Identify flag card", identifyFlagCard("5117 2161 1334 8362")) # Mastercard
print("Validate BR phone number", validateBRPhoneNumber("(11) 91234-5678")) # { 'isValid': True, 'errorMsg': None }

isValidImage Usage Example

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

Looking for contributions.

Available Validation Modules !!! STILL NOT AVALIABLE !!!

  • isAscii: Checks if the string contains only ASCII characters.
  • isBase64: Checks if the string is a valid Base64 encoding.
  • isCEP: CEP validation (Brazilian postal code).
  • isDate: Date format validation.
  • isDecimal: Checks if the number is a decimal.
  • isEmpty: Checks if the string is empty.
  • isMACAddress: MAC address validation.
  • isMD5: Checks if the string is a valid MD5 hash.
  • validatePassportNumber: Passport number validation.
  • isPort: Port number validation.
  • isPostalCode: Postal code validation.
  • isTime: Time format validation.
  • validateEmail: Email address full validation.
  • validatePassword: Password validation.
  • validatePhoneNumber: Phone number validation.
  • validateUsername: Username validation.
  • validateUSPhoneNumber: US phone number validation.
  • isNumber: Checks if the value is a number.
  • validateName: Name validation.
  • validateSurname: Surname validation.
  • validateTextarea: Textarea validation.

For better information, read the documentation

Feel free to explore the various functions and experiment with different inputs to understand their behavior. If you encounter any issues or have suggestions, don't hesitate to reach out to me. Your feedback is valuable and helps improve the package. Happy coding!

By - Gabriel Logan

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multiform_validator-1.0.3.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

multiform_validator-1.0.3-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file multiform_validator-1.0.3.tar.gz.

File metadata

  • Download URL: multiform_validator-1.0.3.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for multiform_validator-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b50729a7a129dece9727de8fa8b09bb3617e1e98be9391481e0d0d58bce037dc
MD5 20fe6850940571ec6307878ae1136b98
BLAKE2b-256 40c1551a4a470e1c697f58d3a18ab984c199db540f9d330fe79d87ae199801e5

See more details on using hashes here.

File details

Details for the file multiform_validator-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for multiform_validator-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f2da46c114ce9e066d3e9eed9353637ddfb15d64cdd8ed421282e65f2087b6ed
MD5 1dcb773136ec1b54023b7658c17f6246
BLAKE2b-256 6a7a00c92d45137fecf612ebc85ed26cb354d9113a61e8751b797fb6ad9514c6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page