tags:

views:

33

answers:

1

What is the XSD syntax, given

<xs:element name="PhoneNumber" type="xs:string" ...? >

, to specify the following format for a phone number:

12 characters and area code is digits.

example of values:

<PhoneNumber>213-555-5845</PhoneNumber>
<PhoneNumber>213-695-CARE</PhoneNumber>
<PhoneNumber>213-4URGENT</PhoneNumber>
+1  A: 

You need to define a simple type deriving from xs:string with a pattern restriction:

  <xs:simpleType name="PhoneNumberType">
    <xs:restriction base="xs:string">
      <xs:pattern value="\d{3}-.{8}"/>
    </xs:restriction>
  </xs:simpleType>

(here the regex requires 3 digits first, then a dash "-", then exactly 8 other characters, for a total of 12 characters.

Then use that type in your phone number element:

<xs:element name="PhoneNumber" type="PhoneNumberType" ...? >

Marc

marc_s
thank you. short and simple.
ShaChris23
it all depends on how complicated your regex will get :-)
marc_s