Java Reference
In-Depth Information
<xs:maxLength value="16" />
</xs:restriction>
</xs:simpleType>
</xs:element>
Note that there is one shortcoming to this regex. I have heard that neither the area code nor
the prefix is allowed to start with a zero or a one for valid U.S. numbers, and this regex does
not capture that idea. However, while I have never seen such a phone number, I also cannot
find that telephonic rule. Moreover, I have found the stricter version of this expression to be
unworkable in the real world, given the millions of records of test data generated by people
who did not know that rule.
Email address
This regex allows typical email addresses that start with an alphanumeric character. It can also
contain hyphens and periods followed by the @ sign and the domain name meeting the same
criteria followed by an alpha suffix between two and nine characters long:
<xs:element name="email">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="(\w+\.)*\w+@(\w+\.)+[A-Za-z]{2,9}" />
<xs:minLength value="6" />
<xs:maxLength value="255" />
</xs:restriction>
</xs:simpleType>
</xs:element>
U.S. postal code
This allows zip (5 digit), or zip+4 in the format 85266-1234:
<xs:element name="usZip">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="\d{5}(-\d{4})?" />
<xs:minLength value="5" />
<xs:maxLength value="10" />
</xs:restriction>
</xs:simpleType>
</xs:element>
Social Security number
This is the standard structure. It does allow for leaving the hyphens off, as they might get
entered by a user with hyphens, but be stored in a database without them:
Search WWH ::




Custom Search