Nil Pun
Nil Pun

Reputation: 17373

XML XSD Regular Expression Check

I would like users to type in telephone number as below:

tel:+6411113100

i.e. the telphone number must start with tel:+

Could someone please show me how to apply the xsd validation to validate the above please?

Thank you.

Upvotes: 1

Views: 765

Answers (3)

Daniel Haley
Daniel Haley

Reputation: 52858

I agree with Michael Kay's answer above concerning sensible design. However, if you really want to restrict the value, here's an example of how you could do it:

  <xsd:simpleType name="telephoneNumber">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="tel:\+\d*"/>
    </xsd:restriction>
  </xsd:simpleType>

Upvotes: 3

Michael Kay
Michael Kay

Reputation: 163332

I would like users to type in telephone number as below: tel:+6411113100

I have to question whether this is a sensible design. For example, phone numbers are often presented with embedded spaces, and I can't see any good reason for preventing users entering the spaces if they wish. To put it another way, I would like to know what the users would like, not what you would like.

Upvotes: 3

Mathias Schwarz
Mathias Schwarz

Reputation: 7197

You need to define a "simple type" for the string. Restrict the type using 'string' as base (to capture also the tel:+ prefix) and use a pattern element to restrict to 'tel:+' followed by digits.

Upvotes: 1

Related Questions