Python Validator
Project description
Validator
Validator is a Python library for dealing with request validating.
Installation (Not Released Yet)
Use the package manager pip to install Validator.
pip install ...
Usage
from validator import Validator
request = {
"firstName": "Jon",
"lastName": "Doe",
"age": 33,
"mail": "jon_doe@gmail.com",
}
rules = {
"firstName": "required",
"lastName": "required",
"age": "required|min:18",
"mail": "required|mail",
}
Validator(request, rules).validate() # returns True
Rules
IP
The field under validation must be an IP address.
>>> IP().check('127.0.0.1')
True
>>> IP().check('0.299.2.1')
False
IPv4
The field under validation must be an IPv4 address.
>>> IPv4().check('127.0.0.1')
True
>>> IPv4().check('0.299.2.1')
False
IPv6
The field under validation must be an IPv6 address.
>>> IPv6().check('2001:0db8:85a3:0000:0000:8a2e:0370:7334')
True
>>> IPv6().check('2001:0db8:85a3:9876:1234:8a2e')
False
Between
The field under validation must have a size between the given min and max
>>> Between(2, 15).check(23)
False
>>> Between(2, 15).check(12)
True
The field under validation must be formatted as an e-mail address
>>> Mail().check('abcd@ef.gh')
True
>>> Mail().check('aaa.com')
False
Max
The field under validation must be less than or equal to a maximum value
>>> Max(18).check(23)
False
>>> Max(18).check(15)
True
Min
The field under validation must be greater than or equal to a minimum value
>>> Min(18).check(23)
True
>>> Min(18).check(15)
False
Required
The field under validation must be present in the input data and not empty
>>> Required().check('Not Empty')
True
>>> Required().check('')
False
RequiredIf
Some Description...
>>> RequiredIf('a').check('abc')
True
>>> RequiredIf('z').check('abc')
False
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for validator-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd06f1b75fcb45b64005e974953478d34e8c2772e87554931513fa157d230e10 |
|
MD5 | da8d3dfe553a218dc9a42eb4665f223f |
|
BLAKE2b-256 | e25dd3db8b8652d644b17f3e62ee591e2069dd4e013a20d295fe106202c22f25 |