Johnston
Johnston

Reputation: 2873

Restricting XML schemas so that user cant put numbers into a string

I have the following code for my schema restriction:

  <xs:simpleType name="myString">
<xs:restriction base="xs:string"/>
 </xs:simpleType>

I was hoping when i made this type that users would not be able to use numbers and characters in their name but it does not restrict this. Is there an easy way to do this?

Thanks

Upvotes: 2

Views: 50

Answers (2)

Alex Aza
Alex Aza

Reputation: 78467

<xs:simpleType name="myString">
    <xs:restriction base="xs:string">
        <xs:pattern value="([^0-9])*"/>
    </xs:restriction>
</xs:simpleType>

Upvotes: 1

Bala R
Bala R

Reputation: 108957

<xs:restriction base="xs:string">
  <xs:pattern value="([a-zA-Z])*"/>
</xs:restriction>

Upvotes: 2

Related Questions