Regular Expressions
Several fields on the CSR enrollment
, CSR generation, and PFX
enrollment pages support using regular expressions to validate that the data entered in the fields meets certain criteria. Both certificate subject fields and metadata
string fields can be configured with regular expressions. The certificate subject fields that support regular expressions are shown in Table 17: Supported Regular Expressions for Enrollment with Examples.
Regular expressions for enrollment can be defined at a global level to apply to all enrollments and at a template level to apply only to enrollments done with that template. Template-level definitions take precedence over global definitions.
Both the regular expressions that do the validation and the error message that the user receives when the validation fails are user definable. For example, for the common name field you could define a regular expression similar to the following:
This regular expression specifies that the data entered in the field must consist of some number of characters in the first portion of the field made up only of lowercase letters, uppercase letters, numbers, apostrophes, underscores, periods, and/or hyphens followed by exactly .keyexample.com. Using this regular expression would prevent users from requesting certificates with common names such as myserver.contoso.com, forcing them to request certificates for domain names that are valid for your organization. Your error message to the user in this case might be something like:
The error message to the user appears immediately once the user leaves the field being validated after entering data that doesn’t meet the regular expression requirements.
Table 17: Supported Regular Expressions for Enrollment with Examples
Subject Part | Example |
---|---|
CN (Common Name) |
This regular expression specifies that the data entered in the field must consist of some number of characters in the first portion of the field made up only of lowercase letters, uppercase letters, numbers, apostrophes, underscores, periods, and/or hyphens followed by exactly .keyexample.com: Copy
The default value for the Common Name regular expression is: Copy
This requires entry of at least one character in the Common Name field in the enrollment pages. |
O (Organization) |
This regular expression requires that the organization name entered in the field be one of “Key Example Inc”, “Key Example” or “Key Example Inc.”: Copy
The period in the final company name (Key Example, Inc.) needs to be escaped in the regular expression with a slash ("\") but the comma does not. |
OU (Organization Unit) |
This regular expression requires that the organizational unit entered in the field be one of these four departments: Copy
|
L (City/ Locality) |
This regular expression requires that the city entered in the field be one of these five cities: Copy
|
ST (State/ Province) |
This regular expression requires that the state entered in the field be one of these eight states: Copy
|
C (Country) |
This regular expression requires that the country entered in the field be either US or CA: Copy
|
E (Email) |
This regular expression specifies that the data entered in the field must consist of some number of characters prior to the “@” made up only of lowercase letters, uppercase letters, numbers, apostrophes, underscores, periods, and/or hyphens followed by exactly “@keyexample.com”: Copy
|
DNS (Subject Alternative Name: DNS Name) |
This regular expression specifies that the data entered in the field must consist of some number of characters in the first portion of the field made up only of lowercase letters, uppercase letters, numbers, apostrophes, underscores, periods, and/or hyphens followed by exactly either “.keyexample1.com” or “.keyexample2.com”: Copy
|
IPv4 (Subject Alternative Name: IPv4 Address) |
This regular expression specifies that the data entered in the field must be exactly “130.101.” followed by anywhere between 1 and 3 numbers followed by exactly “.” followed by anywhere between 1 and 3 numbers: Copy
This regular expression specifies only that the IPv4 address is made up of 4 sets of between 1 and 3 numbers separated by periods: Copy
|
IPv6 (Subject Alternative Name: IPv6 Address) |
This regular expression specifies that the data entered in the field must be made up of eight sets of between one and four numbers and/or uppercase letters separated by colons: Copy
|
MAIL (Subject Alternative Name: Email) |
This regular expression specifies that the data entered in the field must consist of some number of characters prior to the “@” made up only of lowercase letters, uppercase letters, numbers, apostrophes, underscores, periods, and/or hyphens followed by exactly “@keyexample.com”: Copy
|
UPN (Subject Alternative Name: User Principal Name) |
This regular expression specifies that the data entered in the field must consist of some number of characters prior to the “@” made up only of lowercase letters, uppercase letters, numbers, apostrophes, underscores, periods, and/or hyphens followed by exactly “@keyexample.com”: Copy
|
Figure 267: PFX Enrollment Regular Expression Validation Error
For more information about configuring regular expressions on metadata fields, see Certificate Metadata.