|
| 1 | +# Multiform-validator |
| 2 | + |
| 3 | +[](https://badge.fury.io/py/multiform-validator) |
| 4 | +[](https://opensource.org/licenses/MIT) |
| 5 | +[](https://pypistats.org/packages/multiform-validator) |
| 6 | + |
| 7 | +This package provides Python functions to validate various forms fields. |
| 8 | + |
| 9 | +Documentation: https://multiform-validator.vercel.app/documentation/py |
| 10 | + |
| 11 | +Feel free to find bugs and report them to me. Your feedback is highly appreciated. Hugs from Gabriel Logan! |
| 12 | + |
| 13 | +If you want to help me, you can buy me a coffee (: |
| 14 | + |
| 15 | +<p align="center"> |
| 16 | + <a href="https://www.buymeacoffee.com/gabriellogan" target="_blank"> |
| 17 | + <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 50px !important;width: 180px !important;" > |
| 18 | + </a> |
| 19 | +</p> |
| 20 | + |
| 21 | +### Installation |
| 22 | + |
| 23 | +```bash |
| 24 | +pip install multiform-validator |
| 25 | +``` |
| 26 | + |
| 27 | +# Data Validator |
| 28 | + |
| 29 | +This package contains various modules for validating different types of data. Below are the available validation modules: |
| 30 | + |
| 31 | +# Avaliable for while |
| 32 | + |
| 33 | +- **cnpjValidator**: CNPJ validation. |
| 34 | +- **cpfValidator**: CPF validation. |
| 35 | +- **getOnlyEmail**: Extracts only the email or emails address from a string. |
| 36 | +- **identifyFlagCard**: Identifies the flag of a credit card. |
| 37 | +- **isCreditCardValid**: Credit card validation. |
| 38 | +- **isEmail**: Email address validation format. |
| 39 | +- **passwordStrengthTester**: Password strength test. |
| 40 | +- **validateBRPhoneNumber**: Brazilian phone number validation. |
| 41 | +- **isValidImage**: Image validation. |
| 42 | + |
| 43 | +## Usage |
| 44 | + |
| 45 | +Here is an example of how to use the functions in this package: |
| 46 | + |
| 47 | +```python |
| 48 | +from multiform_validator import ( |
| 49 | + cnpjIsValid, |
| 50 | + cpfIsValid, |
| 51 | + getOnlyEmail, |
| 52 | + identifyFlagCard, |
| 53 | + isCreditCardValid, |
| 54 | + isEmail, |
| 55 | + passwordStrengthTester, |
| 56 | + validateBRPhoneNumber, |
| 57 | + isValidImage |
| 58 | +) |
| 59 | +``` |
| 60 | + |
| 61 | +### Usage Example |
| 62 | + |
| 63 | +```python |
| 64 | + |
| 65 | +print( "Is email", isEmail( "[email protected]")) # True |
| 66 | +print( "Get only email", getOnlyEmail( "awdawd wadawd wda awd [email protected] awdawdawd")) # [email protected] |
| 67 | +print("Password strength", passwordStrengthTester("aA1!asd@qd2asd")) # Strong |
| 68 | +print("Is CPF valid", cpfIsValid("123.456.789-02")['isValid']) # False |
| 69 | +print("Is CNPJ valid", cnpjIsValid("12.345.678/0001-09")) # { 'isValid': False, 'errorMsg': 'CNPJ is not valid' } |
| 70 | +print("Is credit card valid", isCreditCardValid("5117 2161 1334 8362")) # True |
| 71 | +print("Identify flag card", identifyFlagCard("5117 2161 1334 8362")) # Mastercard |
| 72 | +print("Validate BR phone number", validateBRPhoneNumber("(11) 91234-5678")) # { 'isValid': True, 'errorMsg': None } |
| 73 | + |
| 74 | +``` |
| 75 | + |
| 76 | +### isValidImage Usage Example |
| 77 | + |
| 78 | +```python |
| 79 | +import os |
| 80 | +from pathlib import Path |
| 81 | + |
| 82 | +from multiform_validator import isValidImage |
| 83 | + |
| 84 | +# Resolve the file path |
| 85 | +file_path = Path.cwd() / 'static' / 'uploads' |
| 86 | +retrieved_file = file_path / filename |
| 87 | + |
| 88 | +# Read the first 4 bytes of the file |
| 89 | +with open(retrieved_file, 'rb') as f: |
| 90 | + file_buffer = f.read(4) |
| 91 | + |
| 92 | +print(isValidImage(file_buffer)) # True or False |
| 93 | +``` |
| 94 | + |
| 95 | +## Functions signature |
| 96 | + |
| 97 | +All params with default values are optional. |
| 98 | + |
| 99 | +```python |
| 100 | + |
| 101 | +def isEmail(email: str) -> bool: |
| 102 | + pass |
| 103 | + |
| 104 | +def getOnlyEmail(text: str, multiple=False, clean_domain=False, repeat_email=False) -> str: |
| 105 | + pass |
| 106 | + |
| 107 | +def passwordStrengthTester(password: str) -> str: |
| 108 | + pass |
| 109 | + |
| 110 | +defaultErrorMsgCPF = [ |
| 111 | + 'CPF invalid', |
| 112 | + 'CPF must have 11 numerical digits', |
| 113 | + 'CPF is not valid', |
| 114 | + 'Unknown error', |
| 115 | +] |
| 116 | +def cpfIsValid(cpf: str, errorMsg=defaultErrorMsgCPF) -> Dict[str, Union[bool, str, None]]: |
| 117 | + pass |
| 118 | + |
| 119 | +default_error_msgCNPJ = [ |
| 120 | + 'CNPJ invalid', |
| 121 | + 'CNPJ must have 14 numerical digits', |
| 122 | + 'CNPJ is not valid', |
| 123 | + 'Unknown error' |
| 124 | +] |
| 125 | +def cnpjIsValid(cnpj: str, errorMsg=default_error_msgCNPJ) -> Dict[str, Union[bool, str, None]]: |
| 126 | + pass |
| 127 | + |
| 128 | +def isCreditCardValid(cardNumber: str) -> bool: |
| 129 | + pass |
| 130 | + |
| 131 | +def identifyFlagCard(cardNumber: str) -> str: |
| 132 | + pass |
| 133 | + |
| 134 | +default_error_msg = ['Invalid value passed', 'Invalid phone number', 'Unknown error'] |
| 135 | +def validateBRPhoneNumber(phoneNumber: str, errorMsg=default_error_msg) -> Dict[str, Union[bool, str, None]]: |
| 136 | + pass |
| 137 | + |
| 138 | +def isValidImage(file_buffer: bytes) -> bool: |
| 139 | + pass |
| 140 | + |
| 141 | +``` |
| 142 | + |
| 143 | +## Looking for contributions. |
| 144 | + |
| 145 | +## Available Validation Modules !!! STILL NOT AVALIABLE !!! |
| 146 | + |
| 147 | +- **isAscii**: Checks if the string contains only ASCII characters. |
| 148 | +- **isBase64**: Checks if the string is a valid Base64 encoding. |
| 149 | +- **isCEP**: CEP validation (Brazilian postal code). |
| 150 | +- **isDate**: Date format validation. |
| 151 | +- **isDecimal**: Checks if the number is a decimal. |
| 152 | +- **isEmpty**: Checks if the string is empty. |
| 153 | +- **isMACAddress**: MAC address validation. |
| 154 | +- **isMD5**: Checks if the string is a valid MD5 hash. |
| 155 | +- **validatePassportNumber**: Passport number validation. |
| 156 | +- **isPort**: Port number validation. |
| 157 | +- **isPostalCode**: Postal code validation. |
| 158 | +- **isTime**: Time format validation. |
| 159 | +- **validateEmail**: Email address full validation. |
| 160 | +- **validatePassword**: Password validation. |
| 161 | +- **validatePhoneNumber**: Phone number validation. |
| 162 | +- **validateUsername**: Username validation. |
| 163 | +- **validateUSPhoneNumber**: US phone number validation. |
| 164 | +- **isNumber**: Checks if the value is a number. |
| 165 | +- **validateName**: Name validation. |
| 166 | +- **validateSurname**: Surname validation. |
| 167 | +- **validateTextarea**: Textarea validation. |
| 168 | + |
| 169 | +### For better information, read the documentation |
| 170 | + |
| 171 | +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! |
| 172 | + |
| 173 | +# By - Gabriel Logan |
0 commit comments