XSD to allow A-Z 0-9 and spaces, but not leading/trailing spaces

Discussion in 'XML' started by johkar, Dec 9, 2009.

  1. johkar

    johkar Guest

    I need an XSD restriction for an attribute that will catch this:
    name=" AD 01 24"

    I need to enforce all caps or numbers or spaces but disallow leading
    or trailing spaces. If I could dissallow double spaces that would be
    a bonus. This is what I have so far:

    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:whiteSpace value="collapse"/>
    <xs:pattern value="([A-Z0-9 -])*"/>
    </xs:restriction>
    </xs:simpleType>
     
    johkar, Dec 9, 2009
    #1
    1. Advertising

  2. johkar

    Peter Flynn Guest

    johkar wrote:
    > I need an XSD restriction for an attribute that will catch this:
    > name=" AD 01 24"
    >
    > I need to enforce all caps or numbers or spaces but disallow leading
    > or trailing spaces. If I could dissallow double spaces that would be
    > a bonus. This is what I have so far:
    >
    > <xs:simpleType>
    > <xs:restriction base="xs:string">
    > <xs:whiteSpace value="collapse"/>
    > <xs:pattern value="([A-Z0-9 -])*"/>
    > </xs:restriction>
    > </xs:simpleType>


    You need to prohibit the leading and trailing spaces separately by
    specifying that the first character must be a letter or digit; followed
    by any mix of letters, digits, spaces, or hyphens; followed by a letter
    or digit. The ^ binds to the start of the expression and the $ binds to
    the end of the expression:

    "^[A-Z0-9][A-Z0-9\ \-]*[A-Z0-9]$"

    That's normal RE syntax. I don't know if that is acceptable within the
    XSD, and I'm uncertain about how to prohibit a double-space.

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
     
    Peter Flynn, Dec 9, 2009
    #2
    1. Advertising

  3. johkar

    Mayeul Guest

    johkar wrote:
    > I need an XSD restriction for an attribute that will catch this:
    > name=" AD 01 24"
    >
    > I need to enforce all caps or numbers or spaces but disallow leading
    > or trailing spaces. If I could dissallow double spaces that would be
    > a bonus. This is what I have so far:
    >
    > <xs:simpleType>
    > <xs:restriction base="xs:string">
    > <xs:whiteSpace value="collapse"/>
    > <xs:pattern value="([A-Z0-9 -])*"/>
    > </xs:restriction>
    > </xs:simpleType>


    Actually <xs:whiteSpace value="collapse"/> should eliminate any leading,
    trailing and multiple spaces before checking the pattern. That would
    prevent invalidation of these spaces.

    --
    Mayeul
     
    Mayeul, Dec 10, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Les Caudle
    Replies:
    0
    Views:
    671
    Les Caudle
    Mar 7, 2004
  2. Generic Usenet Account

    Trimming leading and trailing spaces from a string

    Generic Usenet Account, Jul 8, 2005, in forum: C++
    Replies:
    6
    Views:
    396
    Paul Groke
    Jul 13, 2005
  3. John Nagle
    Replies:
    4
    Views:
    615
    James Antill
    Aug 7, 2007
  4. John B. Matthews
    Replies:
    4
    Views:
    695
    John B. Matthews
    Sep 12, 2008
  5. Roedy Green
    Replies:
    3
    Views:
    658
Loading...

Share This Page