Java Reference
In-Depth Information
<xsd:enumeration value="YT" />
</xsd:restriction>
</xsd:simpleType>
URL
This matches a URL with the http:// optional. https:// is allowable too, as is leaving off
the protocol altogether and just going with something like www.domain.com. Port numbers
are optional too, but if specified they must be between two and five digits in length:
<xs:element name="url">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="(https?://)?[-\w.]+(:\d{2,5})?(/([\w/
_.]*)?)?" />
</xs:restriction>
</xs:simpleType>
</xs:element>
So these are all valid examples:
http://www.domain.com
https://www.domain.com
http://www.domain.com:8080
http://www.domain.com:8080/some.xsd
http://www.domain.com:80/path/doc.xml
IP address
For an IP address, you need to represent values 0-255 across four octets:
<xs:element name="ip">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern
value="(((\d{0,2})|(1(\d){0,2})|(2[0-4]\d)|(25[0-5]))\.){3}
((\d{0,2})|(1(\d){0,2})|(2[0-4]\d)|(25[0-5]))" />
</xs:restriction>
</xs:simpleType>
</xs:element>
This pattern allows 127.0.0.1, 192.168.1.1, 10.0.134.147, and so on.
There are surely many other common types of regular expressions that it would be convenient
to have defined for you, but these should be enough to get you started.
Search WWH ::




Custom Search