Introduction
Web2py is an open-source, agile development framework for developing web applications. It is written in python with a .py extension. The forms in web2py are used to take inputs from users and perform actions on them by storing the data. The data provided by the users must be validated for security and to ensure it is not breached or mishandled. We have validators to handle this validation in web2py. Validators are the classes that are used to validate input fields and provide security to the data. Let’s learn about various validators in web2py in this article.

Database validators
The database validators are used to monitor the data in the database tables. They check whether the data exists in the database are not. Let’s learn the database article with examples.
IS_NOT_IN_DB
This validator checks whether the data or an element is not present in the database. Whenever we try inserting any element into the database, we must check if it already exists to avoid duplicate values.
db.define_table('person', Field(personName, unique=True))
db.person.personName.requires = IS_NOT_IN_DB(dbset, field, error_message='The name already exists in database', allowed_override=[])
dbset: a collection of all the entities to search the name from
Field: contains the name of the person
error_message: displays an error message when the validation fails
allowed_override: defines whether you can override a value in the database
In the above code, the validator checks if the element or person already exists in the database when we try to insert the value.
IS_IN_DB
This validator checks whether the data or an element is present in the database. Whenever we try inserting any element into the database, we must check if it already exists to avoid duplicate values.
db.define_table('person', Field(personName, unique=True))
db.owner.requires = IS_IN_DB(db, 'person.id', 'db.person.personName, error_message=’The name doesn't exist in database’))
The above code checks whether the person with the id person.id and name is in the database. If the name is not in the database, it displays a message: "The name doesn't exist in database”.






