Skip to content

Latest commit

 

History

History
65 lines (42 loc) · 1.39 KB

README.md

File metadata and controls

65 lines (42 loc) · 1.39 KB

Masonite Validation

This package is a standalone component package for the Masonite framework.

Masonite comes with this package out of the box but you can also use this package by itself.

Installing this package does not install the Masonite framework. This only installs the few modules necessary to have validation.


Installation

First pip install it:

$ pip install masonite-validation

Getting Started

To use this package you can import the Validator class at the top:

from masonite.validation import Validator

As well as some rules:

from masonite.validation import Validator, required, exists, accepted

And then specify the rules in this format:

# Validator({dictionary}, *rules, **kwargs)

So for example to validate this payload:

payload = {
    'user': 'username123',
    'company': 'Masonite',
    'terms': 'on' # For checkboxes
}

errors = Validator(
    payload,
    required(['user', 'company', 'terms']),
    accepted('terms')
  )

Errors will either be nothing or an dictionary of error messages

Documentation

You can find extension documentation on available rules at the Masonite Documentation