XML Schema

Associate
Joined
17 Dec 2008
Posts
671
How can I make this so it must be alphanumeric? For example so symbols can't just be typed in.

Code:
<xsd:element name="ItemName" minOccurs="0">
            <xsd:simpleType>
              <xsd:restriction base="sqltypes:nvarchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth">
                <xsd:maxLength value="100"/>
              </xsd:restriction>
            </xsd:simpleType>
          </xsd:element>
 
Code:
<xsd:pattern value="[a-zA-Z0-9 ]+"/>
I found out how to do it now. You have to add a space in there to allow spaces in the item name as well.
 
Last edited:
Thanks. It works without the Asterisk and the plus sign is needed. I don't know if its what the assessment wants me to do, but it works.
Code:
<xsd:pattern value="images\\menuitems\\[a-zA-Z0-9]+.jpg"/>
 
Last edited:
Hmm, it should work with the asterisk, as it means match any number of the preceding characters [a-zA-Z0-9]. The + is a greedy forward match from memory. If you put an example filename in that website, say images\menuitems\Testing123.jpg and use my original RegEx it matches.

Anyway, if it works, it works :p
 
Back
Top Bottom