Validation Expressions in SMOD

Overview

Validation Expressions in SMOD are a powerful way to help guide users to input data into Active Directory in a consistent or desired format.  For example, the different phone number fields in Active Directory are represented by strings, so users could put the phone number in any format.  Through the use of validation expressions, the SMOD administrator could ensure that phone numbers are entered in this format:

 

(214) 555-1212

 

Various other examples for the use of this such as social security numbers, departments, cost centers can be given where this facility can be used with great advantage.

 

Where to input validation expressions

Validation expressions are entered on the Edit Attribute page.  This can be accessed by accessing the Categories page and then - clicking on the Edit icon for existing attributes or when creating a new attribute.  The edit attribute screen is shown here for reference:

 

SMOD_Admin_ValidationExpression.jpg

 

Syntax for validation expression

Validation expressions are strings and use the standard known as Regular Expressions with support provided by Microsoft ASP.NET environment.  A primer on Microsoft's use of regular expressions is given here:

 

.NET Framework Regular Expressions

 

The regular expression syntax allows an efficient method for processing text and pattern matching.  As an example, if you want to make sure a field has a correctly formatted email address, you could use the regular expression:

 

[\w-]+@([\w-]+\.)+[\w-]+

 

This validation expression forces the user to enter a simple email address that contains "@" and a period.

 

Which data types support validation expressions

Validation expressions are only supported for strings so only single value and multi value data types of different string (such as Directory String) are supported.  For all other data types, this field is ignored.

 

 

Common validation expressions

Some common validation expressions are given here that may come in handy and give an idea of how validation expressions can be used:

 

Type Regular Expression Sample
Phone Number in format XXX-YYY-ZZZZ (\d{3})-(\d{3})-(\d{4}) 214-555-1212
Phone Number in format (XXX) YYY-ZZZZ ^([\(]{1}[0-9]{3}[\)]{1}[ ]{1}[0-9]{3}[\-]{1}[0-9]{4})$ (555) 555-1212
Zip Code - U.S. 5 digit or 5+4 ^\d{5}((-|\s)?\d{4})?$ 75234 or 77070-3422
Percentage ^( 100(?:\.0{1,2})? | 0*?\.\d{1,2} | \d{1,2}(?:\.\d{1,2})? )% $ 95% or .25% but not 99.006%
Any positive whole number from 0-999 ^\d(\d)?(\d)?$ 52 or 215
Email Address [\w-]+@([\w-]+\.)+[\w-]+ johndoe@mycompany.com
ISBN Number ISBN\x20(?=.{13}$)\d{1,5}([- ])\d{1,7}\1\d{1,6}\1(\d|X)$ ISBN 0 93028 923 4
Social Security Number (U.S.) ^\d{3}-\d{2}-\d{4}$ 111-22-3333

 

Validation Expressions - get more information

There are numerous web sites that give more information and helpful regular expression libraries that can be used in SMOD.  The search term to use would be "regular expressions".