0% found this document useful (0 votes)
50 views2 pages

Validation Rule Examples

This document provides examples of validation rules that can be applied to fields and tables in a database. Field-level rules validate individual values when entering data, while record-level rules validate entire records. Examples are given for rules limiting values to numbers, dates, ranges, lists, data types, and logical expressions combining rules. Common operators like BETWEEN, IN, IS NULL, AND, and OR are also explained.

Uploaded by

Han Htet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views2 pages

Validation Rule Examples

This document provides examples of validation rules that can be applied to fields and tables in a database. Field-level rules validate individual values when entering data, while record-level rules validate entire records. Examples are given for rules limiting values to numbers, dates, ranges, lists, data types, and logical expressions combining rules. Common operators like BETWEEN, IN, IS NULL, AND, and OR are also explained.

Uploaded by

Han Htet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

VALIDATION RULE EXAMPLES

The following table provides examples of field-level and record-level validation rules, plus
explanatory validation text. You can adapt these examples to fit your content.

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 Date must occur in 2007.
<#01/01/2008#
<Date() Birth date cannot be in the future.
>=Int(Now()) Enter today's date.
M Or F Enter M for male or F for female.

Validation Rules for fields

This rule is applied when you enter data into the field. You cannot tab to the next field until you
enter something that satisfies the rule, or undo your entry.

Examples:

Validation Rule
To do this ... Explanation
for Fields
Accept letters Is Null OR Not Any character outside the range A to Z is rejected. (Case
(a - z) only Like "*[!a-z]*" insensitive.)
Accept digits (0 Is Null OR Not Any character outside the range 0 to 9 is rejected. (Decimal
- 9) only Like "*[!0-9]*" point and negative sign rejected.)
Exactly 8 Is Null OR Like
The question mark stands for one character.
characters "????????"
Is Null OR
Between 1000 For Number fields.
Exactly 4 digits And 9999
Is Null OR Like
For Text fields.
"####"
Positive
Is Null OR >= 0 Remove the "=" if zero is not allowed either.
numbers only
Is Null OR
No more than 100% is 1. Use 0 instead of -1 if negative percentages are not
Between -1 And
100% allowed.
1
Not a future Is Null OR <=
date Date()
You must fill in Same as setting the field's Required property, but lets you
Not Null
Field1 create a custom message (in the Validation Text property.)
Is Null OR "M" It is better to use a lookup table for the list, but this may be
Limit to Or "F" useful for simple choices such as Male/Female.
specific
choices Is Null OR IN (1,
The IN operator may be simpler than several ORs.
2, 4, 8)
The Yes/No field in Access does not support Null as other
Yes/No/Null databases do. To simulate a real Yes/No/Null data type, use
Is Null OR 0 or -1
field a Number field (size Integer) with this rule. (Access uses 0 for
False, and -1 for True.)

Validation Rules for tables

In addition to those rules, the following table shows the common arithmetic operators and
provides examples of how you can use them.

OPERATOR FUNCTION EXAMPLE


NOT Tests for converse values. Use before any NOT > 10 (the same as <=10).
comparison operator except IS NOT NULL.
IN Tests for values equal to existing members IN ("Tokyo","Paris","Moscow")
in a list. Comparison value must be a
comma-separated list enclosed in
parentheses.
BETWEEN Tests for a range of values. You must use BETWEEN 100 AND 1000 (the same
two comparison values — low and high — as >=100 AND <=1000)
and you must separate those values with
the AND separator.
LIKE Matches pattern strings in Text and Memo LIKE "Geo*"
fields.
IS NOT Forces users to enter values in the field. IS NOT NULL
NULL 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.
AND Specifies that all the data that you enter >= #01/01/2007# AND
must be true or fall within limits that you <=#03/06/2008#
specify. NOTE You can also use AND to
combine validation rules. For
example: NOT "UK" AND LIKE "U*".
OR Specifies that one or more pieces of data January OR February
can be true.
< Less than.
<= Less than or equal to.
> Greater than.
>= Greater than or equal to.
= Equal to.

> Not equal to.

You might also like