ShowTable of Contents
You can format an email address field so it only accepts a valid email address format or an email address from a specific domain.
Email addresses only come in one format: a string of alphanumeric characters (which may include punctuation symbols), followed by the @ sign, and concluded with a domain name. There are two primary ways to format email address fields:
- To accept any email address
- To accept only email addresses from a particular domain
Accepting any email address
To format a field to accept any email address (and reject any data that is not an email address), you must create an input constraint pattern. You must use a Unix-style regular expression to specify this pattern. For example, the following regular expression configures a field to accept any email address, but rejects any that do not contain an @ symbol or domain name:
([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)
Accepting only email addresses from a specific domain
To format a field to only accept email addresses from a particular domain, you must create an input constraint pattern that specifies the required domain name. You must use a Unix-style regular expression to specify this pattern. For example, the following regular expression configures a field to accept only email addresses with an IBM® domain:
([a-zA-Z0-9_\-\.]+)@ibm\.com
Examples
The following code sample shows how to create a field that accepts any email address:
<field sid="FIELD24">
<label>E-Mail Address</label>
<format>
<datatype>string</datatype>
<constraints>
<patterns>
<pattern>([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)</pattern>
</patterns>
</constraints>
</format>
<value></value>
</field>
The following code sample shows how to create a field that accepts only email addresses from a particular domain:
<field sid="FIELD25">
<label>E-Mail Address</label>
<format>
<datatype>string</datatype>
<constraints>
<patterns>
<pattern>([a-zA-Z0-9_\-\.]+)@ibm\.com</pattern>
</patterns>
</constraints>
</format>
<value></value>
</field>
Exceptions to this practice
There are no exceptions to this practice.