Restrict data input by using validation rules (2023)

You can vet or validate data in Access desktop databases as you enter it by using validation rules. You can use the expression builder to help you format the rule correctly. Validation rules can be set in either table design or table datasheet view. There are three types of validation rules in Access:

1. Field Validation RuleYou can use a field validation rule to specify a criterion that all valid field values must meet. You should not have to specify the current field as a part of the rule unless you are using the field in a function. Restrictions on types of characters to be entered in a field may be easier to do with an Input Mask.For example, a date field might have a validation rule that disallows values in the past.

Quick examples:

Disallow date values in the past: >=Date()

Generally accepted email format: Is Null OR ((Like "*?@?*.?*") AND (Not Like "*[ ,;]*"))

Number less than or qual to five: <=5

Currency field can't be negative: >=0

Restrict character length in string: Len([StringFieldName])<100

Restrict data input by using validation rules (1)

2. Record Validation RuleYou can use a record validation rule to specify a condition that all valid records must satisfy. You can compare values across different fields using a record validation rule. For example, a record with two date fields might require that values of one field always precede values of the other field (e.g., StartDate is before EndDate).

Quick examples:

Ensure the end date doesn't come before the start date: [End Date]>=[Start Date]

Enter a required date that occurs no more than 30 days after the order date: [RequiredDate]<=[OrderDate]+30

Restrict data input by using validation rules (2)

3. Validation on a formYou can use the Validation Rule property of a control on a form to specify a criterion that all values input to that control must meet. The Validation Rule control property works like a field validation rule. Typically, you use a form validation rule instead of a field validation rule if the rule was specific only to that form and not to the table no matter where it was used.

In this article

  • Overview

  • Add a validation rule to a table

  • Test existing data against a new validation rule

  • Add a validation rule to a control on a form

  • Validation rule reference

Overview

This article explains how to use validation rules and validation text in table fields and form controls. A validation rule is one way to restrict input in a table field or a control (such as a text box) on a form. Validation text lets you provide a message to help users who input data that is not valid.

When data is entered, Access checks to see whether the input breaks a validation rule – if so, the input is not accepted, and Access displays a message.

Access provides a number of ways to restrict input:

  • Data typesEvery table field has a data type that restricts what users can enter. For example, a Date/Time field accepts only dates and times, a Currency field accepts only monetary data, and so on.

  • Field propertiesSome field properties restrict data input. For example, the Field Size property of a field restricts input by limiting the amount of data.

    You can also use the Validation Rule property to require specific values, and the Validation Text property to alert your users to any mistakes. For example, entering a rule such as >100 And <1000 in the Validation Rule property forces users to enter values between 100 and 1,000. A rule such as [EndDate]>=[StartDate] forces users to enter an ending date that occurs on or after a starting date. Entering text such as "Enter values between 100 and 1,000" or "Enter an ending date on or after the start date" in the Validation Text property tells users when they have made a mistake and how to fix the error.

  • Input masksYou can use an input mask to validate data by forcing users to enter values in a specific way. For example, an input mask can force users to enter dates in a European format, such as 2007.04.14.

You can use these methods of validating data alone or in combination with each other. Data types are not optional, and provide the most basic type of data validation.

For more information about data types, field sizes, and input masks, see the article Introduction to data types and field properties.

Types of validation rules

You can create two basic types of validation rules:

  • Field validation rulesUse a field validation rule to check the value that you enter in a field when you leave the field. For example, suppose you have a Date field, and you enter >=#01/01/2010# in the Validation Rule property of that field. Your rule now requires users to enter dates on or after January 1, 2010. If you enter a date earlier than 2010 and then try to place the focus on another field, Access prevents you from leaving the current field until you fix the problem.

  • Record validation rulesUse a record validation rule to control when you can save a record (a row in a table). Unlike a field validation rule, a record validation rule refers to other fields in the same table. You create record validation rules when you need to check the values in one field against the values in another. For example, suppose your business requires you to ship products within 30 days and, if you don't ship within that time, you must refund part of the purchase price to your customer. You can define a record validation rule such as [RequiredDate]<=[OrderDate]+30 to ensure that someone doesn't enter a ship date (the value in the RequiredDate field) too far into the future.

If the syntax for validation rules looks cryptic, see the section What you can put in a validation rule for an explanation of the syntax and some example validation rules.

Where you can use validation rules

You can define validation rules for table fields and for controls on forms. When you define rules for tables, those rules apply when you import data. To add validation rules to a table, you open the table and use commands on the Fields tab of the ribbon. To add validation rules to a form, you open the form in Layout view and add rules to the properties of individual controls.

The steps in the section Add a validation rule to a table explain how to add validation rules to table fields. The steps in the section Add a validation rule to a control on a form, later in this article, explain how to add rules to the properties in individual controls.

What you can put in a validation rule

Your validation rules can contain expressions— functions that return a single value. You can use an expression to perform calculations, manipulate characters, or test data. A validation rule expression tests data. For example, an expression can check for one of a series of values, such as "Tokyo" Or "Moscow" Or "Paris" Or "Helsinki". Expressions can also perform mathematical operations. For example, the expression <100 forces users to enter values that are less than 100. The expression ([OrderDate] - [ShipDate]) calculates the number of days that elapsed between the time an order was placed and the time it shipped.

For more information about expressions, see the article Build an expression.

Top of Page

Add a validation rule to a table

You can add a field validation rule and/or a record validation rule. A field validation rule checks input to a field, and is applied when the focus leaves the field. A record validation rule checks input to one or more fields is applied when the focus leaves the record. Usually, a record validation rule compares the values of two or more fields.

Notes:The following field types do not support validation rules:

  • AutoNumber

  • OLE Object

  • Attachment

  • ReplicationID

Create a field validation rule

  1. Select the field that you want to validate.

  2. On the Fields tab, in the Field Validation group, click Validation, and then click Field Validation Rule.

  3. Use the Expression Builder to create the rule. For more information about using the Expression Builder, see the article Use the Expression Builder.

Create a message to display for field input that is not valid

  1. Select the field that needs a message for input that is not valid. The field should already have a validation rule.

  2. On the Fields tab, in the Field Validation group, click Validation, and then click Field Validation Message.

  3. Enter an appropriate message. For example, if the validation rule is >10, the message might be “Enter a value that is less than 10.”

For some examples of field validation rules and messages, see the section Validation rule reference.

Create a record validation rule

  1. Open the table for which you want to validate records.

  2. On the Fields tab, in the Field Validation group, click Validation, and then click Record Validation Rule.

  3. Use the Expression Builder to create the rule. For more information about using the Expression Builder, see the article Use the Expression Builder.

Create a message to display for record input that is not valid

  1. Open the table that needs a message for input that is not valid. The table should already have a record validation rule.

  2. On the Fields tab, in the Field Validation group, click Validation, and then click Record Validation Message.

  3. Enter an appropriate message. For example, if the validation rule is [StartDate]<[EndDate], themessage might be “StartDate must precede EndDate.”

Top of Page

Test existing data against a new validation rule

If you add a validation rule to an existing table, you might want to test the rule to see whether any existing data is not valid.

  1. Open the table that you want to test in Design View.

    On the Design tab, in the Tools group, click Test Validation Rules.

  2. Click Yes to close the alert message and start the test.

  3. If prompted to save your table, Click Yes.

  4. You might see a variety of other alert messages as you proceed. Read the instructions in each message, and then click Yes or No, as appropriate, to complete or stop the testing.

Top of Page

Add a validation rule to a control on a form

You can use the Validation Rule property and the Validation Text property of a form control to validate data that is input to that control and to help users who input data that is not valid.

Tip:If you create a form automatically from a table by using one of the Form commands on the ribbon, any validation for fields in the underlying table are inherited by the corresponding controls on the form.

A control can have a different validation rule from the table field to which the control is bound. This is useful if you want the form to be more restrictive than the table. The form rule is applied, and then the table rule is applied. If the table is more restrictive than the form, the rule defined for the table field takes precedence. If the rules are mutually exclusive, they prevent you from entering any data at all.

For example, suppose you apply the following rule to a date field in a table:

<#01/01/2010#

But you then apply this rule to the form control that is bound to the date field:

>=#01/01/2010#

The date field now requires values earlier than the year 2010, but the form control requires dates have that year or later, thus preventing you from entering any data at all.

Create a validation rule for a control

  1. Right-click the form that you want to change, and then click Layout View.

  2. Right-click the control that you want to change, and then click Properties to open the property sheet for the control.

  3. Click the All tab, and then enter your validation rule in the Validation Rule property box.

    Tip:Click the Build button to start the Expression Builder.

    For more information about using the Expression Builder, see the article Use the Expression Builder.

  4. Enter a message in the Validation Text property box.

Top of Page

Validation rule reference

Validation rules use Access expression syntax. For more information about expressions, see the article Introduction to expressions.

Validation rule and validation text examples

Validation rule

Validation text

<>0

Enter a nonzero value.

>=0

Value must be zero or greater.

-or-

You must enter a positive number.

0 or >100

Value must be either 0 or greater than 100.

BETWEEN 0 AND 1

Enter a value with a percent sign. (For use with a field that stores number values as percentages).

<#01/01/2007#

Enter a date before 2007.

>=#01/01/2007# AND <#01/01/2008#

Date must occur in 2007.

<Date()

Birth date cannot be in the future.

StrComp(UCase([LastName]),
[LastName],0) = 0

Data in a field named LastName must be uppercase.

>=Int(Now())

Enter today's date.

M Or F

Enter M for male or F for female.

LIKE "[A-Z]*@[A-Z].com" OR "[A-Z]*@[A-Z].net" OR "[A-Z]*@[A-Z].org"

Enter a valid .com, .net, or .org e-mail address.

[RequiredDate]<=[OrderDate]+30

Enter a required date that occurs no more than 30 days after the order date.

[EndDate]>=[StartDate]

Enter an ending date on or after the start date.

Syntax examples for common validation rule operators

Operator

Function

Example

NOT

Tests for converse values. Use before any comparison operator except IS NOT NULL.

NOT > 10 (the same as <=10).

IN

Tests for values equal to existing members in a list. Comparison value must be a comma-separated list enclosed in parentheses.

IN ("Tokyo","Paris","Moscow")

BETWEEN

Tests for a range of values. You must use two comparison values— low and high— and you must separate those values with the AND separator.

BETWEEN 100 AND 1000 (the same as >=100 AND <=1000)

LIKE

Matches pattern strings in Text and Memo fields.

LIKE "Geo*"

IS NOT NULL

Forces users to enter values in the field. This is the same as setting the Required field property to Yes. However, when you enable the Required property and a user fails to enter a value, Access displays a somewhat unfriendly error message. Typically, your database is easier to use if you use IS NOT NULL and enter a friendly message in the Validation Text property.

IS NOT NULL

AND

Specifies that all parts of the validation rule must be true.

>= #01/01/2007# AND <=#03/06/2008#

Note:You can also use AND to combine validation rules. For example: NOT "UK" AND LIKE "U*".

OR

Specifies that some but not all parts of the validation rule must be true.

January OR February

<

Less than.

<=

Less than or equal to.

>

Greater than.

>=

Greater than or equal to.

=

Equal to.

<>

Not equal to.

Using wildcard characters in validation rules

You can use wildcard characters in your validation rules. Keep in mind that Access supports two sets of wildcard characters: ANSI-89 and ANSI-92. Each of those standards uses a different set of wildcard characters.

By default, all .accdb and .mdb files use the ANSI-89 standard.

You can change the ANSI standard for a database to ANSI-92 by using the following procedure:

  1. On the File tab, click Options.

  2. In the Access Options dialog box, click Object Designers.

  3. In the Query design section, under SQL Server Compatible Syntax (ANSI-92), select This database.

For more information about using wildcard characters and the ANSI standards for SQL, see the article Access wildcard character reference.

Top of Page

FAQs

Does validation rule limit data entry? ›

A validation rule is one way to restrict input in a table field or a control (such as a text box) on a form. Validation text lets you provide a message to help users who input data that is not valid.

What is input restriction for validation purpose? ›

Validation should aim to be as accommodating as possible of different forms of input for particular data types. For example, telephone numbers are written with different separators and digit groupings. Your form will be easier to use if it can interpret multiple notations. Also, it is helpful to be liberal with input.

What are the three ways to use validation rules? ›

Use Case of Validation Rules:
  • To limit the number of characters a user is allowed to input. Use case: To notify a user the phone number they entered is invalid.
  • To make sure data is not greater than what is entered. Use case: If a future date is not allowed.
  • To make sure data matches in two different fields.

What type of data you can restrict using the data validation feature? ›

You can use data validation to restrict the type of data or values that users enter into cells. For example, you might use data validation to calculate the maximum allowed value in a cell based on a value elsewhere in the workbook.

What is an example of input validation? ›

For example, validating that an input value is a credit card number may involve validating that the input value contains only numbers, is between 13 and 16 digits long, and passes the business logic check of correctly passing the Luhn formula (the formula for calculating the validity of a number based on the last “ ...

What are the risks of input validation? ›

When software does not validate input properly, an attacker is able to craft the input in a form that is not expected by the rest of the application. This will lead to parts of the system receiving unintended input, which may result in altered control flow, arbitrary control of a resource, or arbitrary code execution.

What are the three levels of input validation controls? ›

There are three types of data validation checks: (1) field checks, (2) record checks, and (3) file checks.

How do you restrict data in a database? ›

To Limit User Access to a Specific Database
  1. Step 1: Create a Matter. ...
  2. Step 2: Associate the Database with the Matter. ...
  3. Step 3: Create a User Group. ...
  4. Step 4: Assign Users to the User Group. ...
  5. Step 5: Associate the User Group with the Matter. ...
  6. Step 6: Remove the Database from the "All user Groups" Matter.

How can data be restricted? ›

Restricted-use data contain sensitive information (i.e., information that can cause potential cause harm if revealed) or information that enables the potential identification of respondents through inference. Data may also be restricted-use because of confidentially promises or proprietariness.

How do you set data restrictions? ›

If you're on an Android device:
  1. Open your phone's Settings app.
  2. Tap Network & internet. Internet.
  3. Next to your carrier, tap Settings .
  4. Tap Data warning & limit.
  5. If it's not already on, turn on Set data limit. Read the on-screen message and tap Ok.
  6. Tap Data limit.
  7. Enter a number. ...
  8. Tap Set.

What are the 4 types of validation? ›

  • A) Prospective validation (or premarket validation)
  • B) Retrospective validation.
  • C) Concurrent validation.
  • D) Revalidation.
Jul 17, 2017

What are data validation rules? ›

What data validation rules are. Data validation rules control what constants can be entered into a cell, e.g. any whole number between 0 and 9, or one of several values from another part of the spreadsheet.

What are two examples of validation? ›

For example, when signing up for a user account on a website, the validation might include:
  • presence check - a username must be entered.
  • length check - a password must be at least eight characters long.
  • range check - age restrictions may require the user's date of birth to be before a certain date.

What are the 4 step processes of data validation? ›

The data Validation process consists of four significant steps.
  • Detail Plan. It is the most critical step, to create the proper roadmap for it. ...
  • Validate the Database. This is responsible for ensuring that all the applicable data is present from source to sink. ...
  • Validate Data Formatting. ...
  • Sampling.
Sep 29, 2022

What are the 3 stages of process validation? ›

The 3 stages of process validation are 1) Process Design, 2) Process Qualification, and 3) Continued Process Verification. Current Good Manufacturing Practices (cGMP) come strongly into play when participating in pharmaceutical process validation activities. A number of them are legally enforceable requirements.

What is a validation check example? ›

Validation is the name given to the process whereby the information entered in the database is checked to ensure that it makes sense. For example, you can use validation to check that only numbers between 0 and 100 are entered in a percentage field, or only Male or Female is entered in a sex field.

Which three data types do not support the validation rules? ›

Answer. Explanation:Validation rules are only applicable to the data types Text, Number, Date/Time, and Yes/No. The other data types (Currency, Memo, OLE Object, AutoNumber, Calculated, and Attachment) do not support validation rules.

What items can be managed by using data validation? ›

Here are just a few examples of what Excel's data validation can do:
  • Allow only numeric or text values in a cell.
  • Allow only numbers within a specified range.
  • Allow data entries of a specific length.
  • Restrict dates and times outside a given range.
  • Restrict entries to a selection from a drop-down list.
Apr 5, 2023

What limits can you set with data validation? ›

There are limits to the number of items that will show in a data validation drop down list:
  • The list can show up to show 32,767 items from a list on the worksheet.
  • If you type the items into the data validation dialog box (a delimited list), the limit is 256 characters, including the separators.
Apr 8, 2023

What is the most common input validation? ›

The most common input validation attack types are buffer overflow attacks, canonicalization attacks, cross-site scripting (XSS) attacks, and SQL injection (SQLi) attacks.

What is data validation with an simple example? ›

Examples of formulas in data validation
To make sure thatEnter this formula
The cell that contains a product name (D2) only contains text.=ISTEXT(D2)
The cell that contains someone's birthday (B6) has to be greater than the number of years set in cell B4.=IF(B6<=(TODAY()-(365*B4)),TRUE,FALSE)
3 more rows

What are the popular input validation techniques? ›

5 Types of Input Validation
  • Correctness. Basic checks that data conforms to its data type. ...
  • Business Rules. Checking the correctness of the data based on business rules. ...
  • Warnings. Validations typically include both strict validations of data and warnings that can be bypassed by users. ...
  • Information Security. ...
  • Risk Controls.
Apr 18, 2017

What are exceptions for input validation? ›

A validation exception occurs if an input value does not match the expected data type, range or pattern of the data field. For example, if a user enters an integer value in a data field that expects a DateTime value, a validation exception occurs.

What are the common mistakes to avoid validation? ›

Common mistakes in concept validation and how to avoid them:
  • Rejecting ideas because they didn't immediately perform well. ...
  • Waiting until you've got full concepts to test. ...
  • Considering the audience as a whole, not as a diverse set of people. ...
  • Forgetting to iterate. ...
  • Choosing the wrong KPIs. ...
  • Choosing the wrong methodology.

What does access do when data is entered that violates a validation rule? ›

Use the ValidationRule property to specify requirements for data entered into a record, field, or control. When data is entered that violates the ValidationRule setting, you can use the ValidationText property to specify the message to be displayed to the user.

How do I restrict records in SQL? ›

If you don't need to omit any rows, you can use SQL Server's TOP clause to limit the rows returned. It is placed immediately after SELECT. The TOP keyword is followed by integer indicating the number of rows to return. In our example, we ordered by price and then limited the returned rows to 3.

When the data entered violates a validation rule? ›

When data is entered that violates a validation rule, Access automatically displays a message box alerting the user to the problem. When you add a new field, you must give the field a name, but you do not have to assign a data type.

What are the different types of data restrictions? ›

Typically, there are four classifications for data: public, internal-only, confidential, and restricted. Let's look at examples for each of those.

What are types of restricted data? ›

Restricted information includes trade secrets, potentially identifiable information (PII), cardholder data (credit cards), or health information. If disclosed, there would be a significant financial or legal impact to the business.

What are examples of restricted data classification? ›

1.4 Restricted Data - Restricted data requires privacy and security protections. Special authorization may be required for use and collection. Examples - data sets with individual Social Security Numbers (or last four of SSN), credit card transaction or cardholder data, patient health data, financial data, etc.

What does restrict data mean? ›

Restrict background data means preventing an app from running in the background when it's not actively in use. It doesn't disable the app or limit its ability to work when launched. You can choose to restrict background data for individual apps or all the apps on your phone.

What is data protection restriction? ›

Individuals have the right to request the restriction or suppression of their personal data. This is not an absolute right and only applies in certain circumstances. When processing is restricted, you are permitted to store the personal data, but not use it.

What does restrict all data mean? ›

Restricting background data puts limits on how and when apps update when you're not using them. Turning off background data means apps can refresh themselves only once you launch the app — they won't be able to update in the background at all.

What are the five steps in validation process? ›

The validation process consists of five steps ; analyze the job, choose your tests, administer the tests, relate the test and the criteria, and cross-validate and revalidate.

What is an example of a validation process? ›

Process Validation Examples

Examples of processes which should be validated include sterilization, aseptic filling, heat treating, plating, and plastic injection molding.

What are the 6 levels of validation? ›

  • SIX LEVELS of VALIDATION.
  • Level One: Stay Awake and Pay Attention.
  • Level Two: Accurate Reflection.
  • Level Three: Stating What Hasn't Been Said Out Loud (“the unarticulated”)
  • Level Four: Validating Using Past History or Biology.
  • Level Five: Normalizing.
  • Level Six: Radical Genuineness.

What are simple validation rules? ›

A simple validation rule is based on a PredefinedGreexRule, which is used in conjunction with the value of a required attribute. The value is entered as DataCapture information in Sterling Business Center.

How do you validate data? ›

Data Validation Methods
  1. Be consistent and follow other data management best practices, such as data organization and documentation.
  2. Document any data inconsistencies you encounter.
  3. Check all datasets for duplicates and errors.
  4. Use data validation tools (such as those in Excel and other software) where possible.
Apr 10, 2023

How does data validation work? ›

Data validation is a feature in Excel which is used to control what users can enter into a cell. It allows you to dictate specific rules. It also allows users to display a custom message if users try to enter invalid data.

What methods require validation? ›

Q: What methods require validation?
  • Identification tests.
  • Quantitative tests for impurities content.
  • Limit tests for the control of impurities.
  • Quantitative tests of the active moiety in samples of drug substance or drug product or other selected component(s) in the drug product.

What are the limits of validation rules? ›

Increase the 'Active Validation Rules' limit
  • Group: 0.
  • Contact Manager: 20.
  • Essentials: 20.
  • Professional: 20.
  • Enterprise & Developer: 100.
  • Unlimited & Performance: 500.
Mar 20, 2023

Does validation stop all data entry errors? ›

Validation does not stop incorrect data from being entered, however it does ensure that data is: Sensible, reasonable, within acceptable boundaries and complete. Checks that can be applied fall into several categories: Range, type, presence, length, lookup, picture and check digit.

What are three 3 critical aspects of validation? ›

Reviewing assessment practice

Validators must look at the evidence in the sample, and determine if it is valid, reliable, sufficient, current and authentic.

When can a validation rule be used to prevent invalid data? ›

When records are edited by a user - If a user is updating any records user might know or might not know what kind of information needs to be entered into the fields.So validation rule can be used here to prevent invalid data.

How do you prevent data entry errors? ›

How to Prevent Data Entry Mistakes
  1. Train Them on the Importance of Data. The first step for avoiding data entry errors is to express to employees how valuable the information is. ...
  2. Provide a Good Working Environment. ...
  3. Avoid Overloading. ...
  4. Hire Sufficient Staff. ...
  5. Prioritize Accuracy Over Speed. ...
  6. Use Software Tools. ...
  7. Double-Check Work.
Mar 28, 2023

Why not use a validation set? ›

The validation set is used for hyperparameter tuning. The test set is used for the final evaluation of the best model. The validation set is not needed (redundant) if you're not going to perform hyperparameter tuning.

What is the risk of not validating data? ›

Missing or improper input validation is a major factor in many web security vulnerabilities, including cross-site scripting (XSS) and SQL injection. Let's see why proper data validation is so important for application security – but also why it cannot be your only line of defense. Your Information will be kept private.

What are exceptions for data validation? ›

A validation exception occurs if an input value does not match the expected data type, range or pattern of the data field. For example, if a user enters an integer value in a data field that expects a DateTime value, a validation exception occurs. This class uses the ValidationAttribute class to customize validations.

What is the weakest data validation strategy? ›

Encode Known bad (Sanitise)Encode Known Bad: This is the weakest approach.

What should data validation prevent? ›

Data validation is the process of checking the accuracy and quality of data before it is entered into a database or a spreadsheet. Data validation can help you avoid errors, inconsistencies, and duplicates that can affect your analysis and reporting.

References

Top Articles
Latest Posts
Article information

Author: Velia Krajcik

Last Updated: 12/24/2023

Views: 5750

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Velia Krajcik

Birthday: 1996-07-27

Address: 520 Balistreri Mount, South Armand, OR 60528

Phone: +466880739437

Job: Future Retail Associate

Hobby: Polo, Scouting, Worldbuilding, Cosplaying, Photography, Rowing, Nordic skating

Introduction: My name is Velia Krajcik, I am a handsome, clean, lucky, gleaming, magnificent, proud, glorious person who loves writing and wants to share my knowledge and understanding with you.