Leveraging Validation Settings
Another means of ensuring that
the correct data is entered into columns in a list and library is
through the use of validation settings, which can be added to the list
or library on the List Settings or Library Settings page, or to an
individual column. The equations that can be used are more limited, as
the result of the equation must equal the value True or the user won’t
be able to save the entry.
A simple example is
Assuming the value in
ColumnA is greater than ColumnB, the formula generates the value True
and therefore passes the validation test.
Building on the list created in the previous section, follow these steps to add validation to the CalculatedColumnTest list:
1. | Navigate
to the CalculatedColumnTest created in the previous section that
contains the columns Title, Cost, and Sell Price, as described in the
example, as well as sample data, as shown in Figure 22.6.
|
2. | Click the List tab on the Ribbon, and then click Create Column.
|
3. | Enter Invoice Number as the column name, and then choose Single Line of Text.
|
4. | Scroll down to the Description field and enter Enter a valid invoice number starting with "2010-" and then up to 4 digits.
|
5. | Click Enforce Unique Values.
|
6. | Enter 9 for Maximum Number of Characters.
|
7. | Expand the Column Validation section by clicking the + and enter the following in the Formula field:
=FIND("2010-",[Invoice Number], 1)
The FIND function is also defined in Excel 2010 Help, and the syntax
translates to “FIND(find_text, within_text, [start_num]),” or in this
example to “Find the string 2010- in the column Invoice Number, starting
with the first character in the string and the value is True.” This
logic is pretty hard for a careless or even malicious user to beat
because there is a limit of nine characters that can be entered in the
field and it must include the string 2010-. Furthermore, the entry must
be unique.
|
8. | Finally, enter the following in the User Message field: You have entered an invalid invoice number (see Figure 2). Click OK to save.
|
9. | Click OK to the message stating: “This column must be indexed to enforce unique values. Do you want to index this column?”
|
10. | Click Add New Item and enter the title as Whoozit, the Cost as 100, the Sell Price as 150, and Invoice Number as 123456789. Click Save. A red error message will display, stating “The validation formula has evaluated to an error,” as shown in Figure 3, because this invoice number doesn’t meet the validation.
|
11. | Reenter the invoice number as 2010-123 and click Save; this time the entry succeeds because it meets the validation requirements.
|
Enforcing Unique Values in Columns
Certain column types
offer the option to Enforce Unique Values for the column. This is a
capability that has been requested by many clients over the years, and
various workarounds were developed using workflows or leveraging the ID
value of the list item. For example, a list that tracks serial numbers,
employee IDs, invoices, or many other values will be less valuable if
data entry errors can lead to nonunique numbers.
Table 1 summarizes what column types can and cannot be used to create unique columns.
Table 1. Unique Column Options
Supported Unique Column Types | Unsupported Unique Column Types |
---|
Single line of text | Multiple lines of text |
Choice (single value) | Choice (multivalued) |
Number | Calculated |
Currency | Hyperlink or Picture |
Date and Time | Custom Columns |
Lookup (single value) | Lookup (multivalued) |
Managed Metadata | Person or Group
Yes/No |
Caution
If Content Approval is
enabled for a document library and then unique values are enabled, a
warning note displays that “This list or document library has content
approval enabled. A column that enforces unique values may let users
determine information about a list item or document even if they do not
have permission to view it.” This is logical because when a user sees an
error about the item not being a unique value, she can deduce that
there already exists a list item with that value.