# tornado-validator **Repository Path**: oldsyang/tornado-validator ## Basic Information - **Project Name**: tornado-validator - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-05-21 - **Last Updated**: 2021-05-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # tornado-validator ![Travis-CI](https://travis-ci.org/oldsyang/tornado-validator.svg) ## Install: ```bash pip install tornado_validator ``` ## Usage: ### Use default decorators and validators ```python @GET('check_phone_type', type='int', validators='required | in: 1,2,3') @POST('phone', validators='required | regex: \d{11}') @POST('token', validators='required') def post(request, check_phone_type, phone, token): pass ``` ### Custom validator ```python class PhoneNumberValidator(BaseValidator): def is_valid(self, value, params): return True ValidatorRegistry.register('phone_number_validator', PhoneNumberValidator) @POST('phone', validators='required | regex: \d{11} | phone_number_validator') # or @POST('phone', validators='required | regex: \d{11}', validator_classes=[PhoneNumberValidator()]) ``` ## Decorators - GET - POST - POST_OR_GET - FILE - HEADER - URI ## Params for decorator - name: The key of param in the request. - related_name: The key of param to pass throw the function. Default is equals to name. - verbose_name: The key for display in the validation error message. Default is equals to name. - default: Default value for the param. Default is `None`. - type: Auto check and convert the param type. Default is string. - many: Convert the param to a list if set to `True`. - separator: If set many to `True`, use this value to split the param. - validators: String format validator, like `required | max: 1`. ## Default types - str, string - int, integer - float - bool, boolean ## Default validators - required - required_with - required_without - required_if - max - min - between - regex - integer - numeric - in - not_in - ext_in - ext_not_in ## Run tests scripts/test.sh