views:

445

answers:

2

Hi all,

I don't understand why this regular expression for validation international phone number gives an error when embedded on xml-schema:

<xs:simpleType name="phoneType">
  <xs:restriction base="xs:string">
      <xs:pattern value="^\+(?:[0-9] ?){6,14}[0-9]$" />
  </xs:restriction>
</xs:simpleType>

What's wrong with it? Does support group matching? Why is not supported by Xml Schema ?

Thank you very much.

Indrit

A: 

It's probably the anchors (^ and $). In XML Schema, all regexes are implicitly anchored at both ends. Explicit anchors are not supported.

Alan Moore
Hi Alan, thank you too, probably you are right too but in this case the problem wasn't related to anchors. Thank you very much.Indrit
Indrit
+1  A: 

XML schema supports group matching, but not capturing or lookaround. This means that it doesn't the ?: non-capturing group.

According to http://www.regular-expressions.info/xml.html it also doesn't support the ^ and $ anchors.

gibbss
Hi solomon-gibbs, thank you for your answer. I think your are right, schemas doesn't support non capturing groups; because I already tried to delete anchors but the problem was still there. Thank you again.Indrit
Indrit