-
Notifications
You must be signed in to change notification settings - Fork 4
Form Validation Library
Trevor Geene edited this page Jan 4, 2021
·
8 revisions
THIS PAGE IS CURRENTLY OUT OF DATE
Install Nessicary Requirements:
pip install validators
Call Library: from application.libraries.form_validation import form_validation
Rule | Example |
---|---|
Required | required |
Field Match | matches[form_item] |
Field Differs | differs[form_item] |
Field Regex Match | regex_match[/regex/] |
Minimum Length | min_length[3] |
Maximum Length | max_length[12] |
Exact Length | exact_length[8] |
Greater Than | greater_than[8] |
Greater Than/Equal To | greater_than_equal_to[8] |
Less Than | less_than[8] |
Less Than/Equal To | less_than_equal_to[8] |
In List | in_list[red,blue,green] |
In Database* | in_db[table.field] |
Letters Only | alpha |
Letters, Dashes, & Underscores Only | alpha_dash |
Letters & Numbers Only | alpha_numeric |
Letters, Numbers, Dashes, & Underscores Only | alpha_numeric_dash |
Letters & Spaces Only | alpha_spaces |
Letters, Numbers, & Spaces Only | alpha_numeric_spaces |
Numbers Only | numeric |
Valid Email | valid_email |
Valid URL | valid_url |
*Requires database configuration
form_validation.add_field('email', "Email", 'required')
form_validation.add_field('password', "Password", 'required')
form = form_validation.validate()
if form['errors']:
errors_list = form['errors']
else:
post = form['inputs']