Difference between revisions of "The phone number parser"

From Catglobe Wiki
Jump to: navigation, search
 
Line 23: Line 23:
 
''ReadOnlyCollection<string> Examples''  
 
''ReadOnlyCollection<string> Examples''  
  
 
+
<br> '''The following is the default example of how the XML is to be formatted with hints inside the XML.'''&nbsp;  
'''The following is the default example of how the XML is to be formatted with hints inside the XML.'''&nbsp;  
 
  
 
<br>  
 
<br>  
  
&lt;?xml version="1.0" encoding="utf-8" ?&gt;
+
&lt;?xml version="1.0" encoding="utf-8"&nbsp;?&gt;  
  
&lt;xs:schema id="Phonenumber"
+
&lt;xs:schema id="Phonenumber"  
  
targetNamespace="http://catglobe.com/Phonenumber.xsd"
+
targetNamespace="http://catglobe.com/Phonenumber.xsd"  
  
elementFormDefault="qualified"
+
elementFormDefault="qualified"  
  
xmlns="http://catglobe.com/Phonenumber.xsd"
+
xmlns="http://catglobe.com/Phonenumber.xsd"  
  
xmlns:mstns="http://catglobe.com/Phonenumber.xsd"
+
xmlns:mstns="http://catglobe.com/Phonenumber.xsd"  
  
xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
+
xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;  
  
&lt;xs:complexType name="NumberNode"&gt;
+
&lt;xs:complexType name="NumberNode"&gt;  
  
&lt;xs:attribute name="area" use="optional"&gt;
+
&lt;xs:attribute name="area" use="optional"&gt;  
  
&lt;xs:annotation&gt;
+
&lt;xs:annotation&gt;  
  
&lt;xs:documentation&gt;
+
&lt;xs:documentation&gt;  
  
Must adhere to normal regular expressions for selecting digits. Only the chars []^-{} and 0 to 9 us accepted.
+
Must adhere to normal regular expressions for selecting digits. Only the chars []^-{} and 0 to 9 us accepted.  
  
Example: 0[12]3[^4-6]\d{1,2}\d{3} will find a number starting with 0, followed by a 1 or 2, followed by a 3 and then NOT followed by a 4, 5 or 6. After this is then 1 to 2 digits, followed by 3 digits.
+
Example: 0[12]3[^4-6]\d{1,2}\d{3} will find a number starting with 0, followed by a 1 or 2, followed by a 3 and then NOT followed by a 4, 5 or 6. After this is then 1 to 2 digits, followed by 3 digits.  
  
&lt;/xs:documentation&gt;
+
&lt;/xs:documentation&gt;  
  
&lt;/xs:annotation&gt;
+
&lt;/xs:annotation&gt;  
  
&lt;xs:simpleType&gt;
+
&lt;xs:simpleType&gt;  
  
&lt;xs:restriction base="xs:string"&gt;
+
&lt;xs:restriction base="xs:string"&gt;  
  
&lt;xs:pattern value='[-\[\],0-9\\d\{\}]*'/&gt;
+
&lt;xs:pattern value='[-\[\],0-9\\d\{\}]*'/&gt;  
  
&lt;/xs:restriction&gt;
+
&lt;/xs:restriction&gt;  
  
&lt;/xs:simpleType&gt;
+
&lt;/xs:simpleType&gt;  
  
&lt;/xs:attribute&gt;
+
&lt;/xs:attribute&gt;  
  
&lt;xs:attribute name="areadoc" type="xs:string" use="optional"/&gt;
+
&lt;xs:attribute name="areadoc" type="xs:string" use="optional"/&gt;  
  
&lt;xs:attribute name="number" use="required"&gt;
+
&lt;xs:attribute name="number" use="required"&gt;  
  
&lt;xs:annotation&gt;
+
&lt;xs:annotation&gt;  
  
&lt;xs:documentation&gt;
+
&lt;xs:documentation&gt;  
  
Must adhere to normal regular expressions for selecting digits. Only the chars []^-{} and 0 to 9 is accepted.
+
Must adhere to normal regular expressions for selecting digits. Only the chars []^-{} and 0 to 9 is accepted.  
  
Example: 0[12]3[^4-6]\d{1,2}\d{3} will find a number starting with 0, followed by a 1 or 2, followed by a 3 and then NOT followed by a 4, 5 or 6. After this is then 1 to 2 digits, followed by 3 digits.
+
Example: 0[12]3[^4-6]\d{1,2}\d{3} will find a number starting with 0, followed by a 1 or 2, followed by a 3 and then NOT followed by a 4, 5 or 6. After this is then 1 to 2 digits, followed by 3 digits.  
  
&lt;/xs:documentation&gt;
+
&lt;/xs:documentation&gt;  
  
&lt;/xs:annotation&gt;
+
&lt;/xs:annotation&gt;  
  
&lt;xs:simpleType&gt;
+
&lt;xs:simpleType&gt;  
  
&lt;xs:restriction base="xs:string"&gt;
+
&lt;xs:restriction base="xs:string"&gt;  
  
&lt;xs:pattern value='[-\[\],0-9\\d\{\}]*'/&gt;
+
&lt;xs:pattern value='[-\[\],0-9\\d\{\}]*'/&gt;  
  
&lt;/xs:restriction&gt;
+
&lt;/xs:restriction&gt;  
  
&lt;/xs:simpleType&gt;
+
&lt;/xs:simpleType&gt;  
  
&lt;/xs:attribute&gt;
+
&lt;/xs:attribute&gt;  
  
&lt;xs:attribute name="numberdoc" type="xs:string" use="optional"/&gt;
+
&lt;xs:attribute name="numberdoc" type="xs:string" use="optional"/&gt;  
  
&lt;/xs:complexType&gt;
+
&lt;/xs:complexType&gt;  
  
&lt;xs:complexType name="PhoneNumNode"&gt;
+
&lt;xs:complexType name="PhoneNumNode"&gt;  
  
&lt;xs:sequence&gt;
+
&lt;xs:sequence&gt;  
  
&lt;xs:element name="possiblenumber" type="NumberNode" minOccurs="1" maxOccurs="unbounded"/&gt;
+
&lt;xs:element name="possiblenumber" type="NumberNode" minOccurs="1" maxOccurs="unbounded"/&gt;  
  
&lt;/xs:sequence&gt;
+
&lt;/xs:sequence&gt;  
  
&lt;xs:attribute name="trunk" use="optional"&gt;
+
&lt;xs:attribute name="trunk" use="optional"&gt;  
  
&lt;xs:simpleType&gt;
+
&lt;xs:simpleType&gt;  
  
&lt;xs:restriction base="xs:positiveInteger"&gt;
+
&lt;xs:restriction base="xs:positiveInteger"&gt;  
  
&lt;xs:pattern value='[0-9]'/&gt;
+
&lt;xs:pattern value='[0-9]'/&gt;  
  
&lt;/xs:restriction&gt;
+
&lt;/xs:restriction&gt;  
  
&lt;/xs:simpleType&gt;
+
&lt;/xs:simpleType&gt;  
  
&lt;/xs:attribute&gt;
+
&lt;/xs:attribute&gt;  
  
&lt;xs:attribute name="display" use="optional"&gt;
+
&lt;xs:attribute name="display" use="optional"&gt;  
  
&lt;xs:annotation&gt;
+
&lt;xs:annotation&gt;  
  
&lt;xs:documentation&gt;
+
&lt;xs:documentation&gt;  
  
Can contain digits, space or -. A digit will mean "consume this many digits from the number and display", any other char is displayed as is.
+
Can contain digits, space or -. A digit will mean "consume this many digits from the number and display", any other char is displayed as is.  
  
&lt;/xs:documentation&gt;
+
&lt;/xs:documentation&gt;  
  
&lt;/xs:annotation&gt;
+
&lt;/xs:annotation&gt;  
  
&lt;xs:simpleType&gt;
+
&lt;xs:simpleType&gt;  
  
&lt;xs:restriction base="xs:string"&gt;
+
&lt;xs:restriction base="xs:string"&gt;  
  
&lt;xs:pattern value='[-0-9]*'/&gt;
+
&lt;xs:pattern value='[-0-9]*'/&gt;  
  
&lt;/xs:restriction&gt;
+
&lt;/xs:restriction&gt;  
  
&lt;/xs:simpleType&gt;
+
&lt;/xs:simpleType&gt;  
  
&lt;/xs:attribute&gt;
+
&lt;/xs:attribute&gt;  
  
&lt;/xs:complexType&gt;
+
&lt;/xs:complexType&gt;  
  
&lt;xs:complexType name="CountryNode"&gt;
+
&lt;xs:complexType name="CountryNode"&gt;  
  
&lt;xs:sequence&gt;
+
&lt;xs:sequence&gt;  
  
&lt;xs:element name="mobile" type="PhoneNumNode" maxOccurs="1"/&gt;
+
&lt;xs:element name="mobile" type="PhoneNumNode" maxOccurs="1"/&gt;  
  
&lt;xs:element name="landline" type="PhoneNumNode" maxOccurs="1"/&gt;
+
&lt;xs:element name="landline" type="PhoneNumNode" maxOccurs="1"/&gt;  
  
&lt;xs:element name="example" type="xs:string" minOccurs="0" maxOccurs="unbounded"/&gt;
+
&lt;xs:element name="example" type="xs:string" minOccurs="0" maxOccurs="unbounded"/&gt;  
  
&lt;/xs:sequence&gt;
+
&lt;/xs:sequence&gt;  
  
&lt;xs:attribute name="countrycode" type="xs:ID" use="required"&gt;
+
&lt;xs:attribute name="countrycode" type="xs:ID" use="required"&gt;  
  
&lt;xs:annotation&gt;
+
&lt;xs:annotation&gt;  
  
&lt;xs:documentation&gt;
+
&lt;xs:documentation&gt;  
  
Prefix to call country. e.g. 45 for Denmark. Must be unique.
+
Prefix to call country. e.g. 45 for Denmark. Must be unique.  
  
&lt;/xs:documentation&gt;
+
&lt;/xs:documentation&gt;  
  
&lt;/xs:annotation&gt;
+
&lt;/xs:annotation&gt;  
  
&lt;/xs:attribute&gt;
+
&lt;/xs:attribute&gt;  
  
&lt;/xs:complexType&gt;
+
&lt;/xs:complexType&gt;  
  
 +
<br>
  
 +
&lt;xs:element name="Phonenumbers"&gt;
  
&lt;xs:element name="Phonenumbers"&gt;
+
&lt;xs:annotation&gt;  
  
&lt;xs:annotation&gt;
+
&lt;xs:documentation&gt;  
  
&lt;xs:documentation&gt;
+
&lt;![CDATA[
  
&lt;![CDATA[
+
&lt;Phonenumbers&gt;
  
&lt;Phonenumbers&gt;
+
&lt;country countrycode="31"&gt;  
  
&lt;country countrycode="31"&gt;
+
&lt;mobile trunk="0" display="3-3-3"&gt;  
  
&lt;mobile trunk="0" display="3-3-3"&gt;
+
&lt;possiblenumber number="6\\d{8}" numberdoc="A 6 followed by 8 digits"/&gt;  
  
&lt;possiblenumber number="6\\d{8}" numberdoc="A 6 followed by 8 digits"/&gt;
+
&lt;/mobile&gt;  
  
&lt;/mobile&gt;
+
&lt;landline trunk="0" display="3-3-3"&gt;  
  
&lt;landline trunk="0" display="3-3-3"&gt;
+
&lt;possiblenumber area="[1-5]0" areadoc="1 to 5 followed by a zero" number="\d{7}" numberdoc="7 digits"/&gt;  
  
&lt;possiblenumber area="[1-5]0" areadoc="1 to 5 followed by a zero" number="\d{7}" numberdoc="7 digits"/&gt;
+
...
  
...
+
&lt;/landline&gt;
  
&lt;/landline&gt;
+
&lt;example&gt;blabla +31 666 666 666&lt;/example&gt;  
  
&lt;example&gt;blabla +31 666 666 666&lt;/example&gt;
+
&lt;example&gt;blablabla2&lt;/example&gt;  
  
&lt;example&gt;blablabla2&lt;/example&gt;
+
&lt;/country&gt;  
  
&lt;/country&gt;
+
...
  
...
+
&lt;/Phonenumbers&gt;  
 
 
&lt;/Phonenumbers&gt;
 
  
 
]]&gt;
 
]]&gt;
  
&lt;/xs:documentation&gt;
+
&lt;/xs:documentation&gt;  
  
&lt;/xs:annotation&gt;
+
&lt;/xs:annotation&gt;  
  
&lt;xs:complexType&gt;
+
&lt;xs:complexType&gt;  
  
&lt;xs:sequence&gt;
+
&lt;xs:sequence&gt;  
  
&lt;xs:element name="country" type="CountryNode" minOccurs="1" maxOccurs="unbounded"/&gt;
+
&lt;xs:element name="country" type="CountryNode" minOccurs="1" maxOccurs="unbounded"/&gt;  
  
&lt;/xs:sequence&gt;
+
&lt;/xs:sequence&gt;  
  
&lt;xs:attribute name="date" type="xs:date" use="required"&gt;
+
&lt;xs:attribute name="date" type="xs:date" use="required"&gt;  
  
&lt;xs:annotation&gt;
+
&lt;xs:annotation&gt;  
  
&lt;xs:documentation&gt;
+
&lt;xs:documentation&gt;  
  
If this date is before the system rules date, then the system rules will be used instead.
+
If this date is before the system rules date, then the system rules will be used instead.  
  
&lt;/xs:documentation&gt;
+
&lt;/xs:documentation&gt;  
  
&lt;/xs:annotation&gt;
+
&lt;/xs:annotation&gt;  
  
&lt;/xs:attribute&gt;
+
&lt;/xs:attribute&gt;  
  
&lt;/xs:complexType&gt;
+
&lt;/xs:complexType&gt;  
  
&lt;/xs:element&gt;
+
&lt;/xs:element&gt;  
  
 +
<br>
  
 +
&lt;/xs:schema&gt;<br>
  
&lt;/xs:schema&gt;<br>
+
<br>  
  
<br>
+
<br>  
  
<br>
+
<br>  
  
<br>
+
<br>  
 
 
<br>
 
  
&nbsp;&nbsp;
+
&nbsp;&nbsp;  
  
 
[[Category:Language_and_culture_settings]]
 
[[Category:Language_and_culture_settings]]

Latest revision as of 10:08, 24 February 2012



The phone number parser

The phone number parser makes it possible to decide which format phone numbers are legal for different countries.

LangCult5-5-1

To update the rules simply download the XML file, then update it using the syntax specified in the file, and finally upload it again.

The new XML format contains examples and documentation hints for each possible phonenumber. The API for phonenumber parsing should allow any user of the API to get a class containing a ReadOnlyCollection of the following for a country:

string AreaCodeRegExp

string AreaCodeDocumentation

string NumberRegExp

string NumberDocumentation

Plus also a

ReadOnlyCollection<string> Examples


The following is the default example of how the XML is to be formatted with hints inside the XML. 


<?xml version="1.0" encoding="utf-8" ?>

<xs:schema id="Phonenumber"

targetNamespace="http://catglobe.com/Phonenumber.xsd"

elementFormDefault="qualified"

xmlns="http://catglobe.com/Phonenumber.xsd"

xmlns:mstns="http://catglobe.com/Phonenumber.xsd"

xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:complexType name="NumberNode">

<xs:attribute name="area" use="optional">

<xs:annotation>

<xs:documentation>

Must adhere to normal regular expressions for selecting digits. Only the chars []^-{} and 0 to 9 us accepted.

Example: 0[12]3[^4-6]\d{1,2}\d{3} will find a number starting with 0, followed by a 1 or 2, followed by a 3 and then NOT followed by a 4, 5 or 6. After this is then 1 to 2 digits, followed by 3 digits.

</xs:documentation>

</xs:annotation>

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:pattern value='[-\[\],0-9\\d\{\}]*'/>

</xs:restriction>

</xs:simpleType>

</xs:attribute>

<xs:attribute name="areadoc" type="xs:string" use="optional"/>

<xs:attribute name="number" use="required">

<xs:annotation>

<xs:documentation>

Must adhere to normal regular expressions for selecting digits. Only the chars []^-{} and 0 to 9 is accepted.

Example: 0[12]3[^4-6]\d{1,2}\d{3} will find a number starting with 0, followed by a 1 or 2, followed by a 3 and then NOT followed by a 4, 5 or 6. After this is then 1 to 2 digits, followed by 3 digits.

</xs:documentation>

</xs:annotation>

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:pattern value='[-\[\],0-9\\d\{\}]*'/>

</xs:restriction>

</xs:simpleType>

</xs:attribute>

<xs:attribute name="numberdoc" type="xs:string" use="optional"/>

</xs:complexType>

<xs:complexType name="PhoneNumNode">

<xs:sequence>

<xs:element name="possiblenumber" type="NumberNode" minOccurs="1" maxOccurs="unbounded"/>

</xs:sequence>

<xs:attribute name="trunk" use="optional">

<xs:simpleType>

<xs:restriction base="xs:positiveInteger">

<xs:pattern value='[0-9]'/>

</xs:restriction>

</xs:simpleType>

</xs:attribute>

<xs:attribute name="display" use="optional">

<xs:annotation>

<xs:documentation>

Can contain digits, space or -. A digit will mean "consume this many digits from the number and display", any other char is displayed as is.

</xs:documentation>

</xs:annotation>

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:pattern value='[-0-9]*'/>

</xs:restriction>

</xs:simpleType>

</xs:attribute>

</xs:complexType>

<xs:complexType name="CountryNode">

<xs:sequence>

<xs:element name="mobile" type="PhoneNumNode" maxOccurs="1"/>

<xs:element name="landline" type="PhoneNumNode" maxOccurs="1"/>

<xs:element name="example" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>

</xs:sequence>

<xs:attribute name="countrycode" type="xs:ID" use="required">

<xs:annotation>

<xs:documentation>

Prefix to call country. e.g. 45 for Denmark. Must be unique.

</xs:documentation>

</xs:annotation>

</xs:attribute>

</xs:complexType>


<xs:element name="Phonenumbers">

<xs:annotation>

<xs:documentation>

<![CDATA[

<Phonenumbers>

<country countrycode="31">

<mobile trunk="0" display="3-3-3">

<possiblenumber number="6\\d{8}" numberdoc="A 6 followed by 8 digits"/>

</mobile>

<landline trunk="0" display="3-3-3">

<possiblenumber area="[1-5]0" areadoc="1 to 5 followed by a zero" number="\d{7}" numberdoc="7 digits"/>

...

</landline>

<example>blabla +31 666 666 666</example>

<example>blablabla2</example>

</country>

...

</Phonenumbers>

]]>

</xs:documentation>

</xs:annotation>

<xs:complexType>

<xs:sequence>

<xs:element name="country" type="CountryNode" minOccurs="1" maxOccurs="unbounded"/>

</xs:sequence>

<xs:attribute name="date" type="xs:date" use="required">

<xs:annotation>

<xs:documentation>

If this date is before the system rules date, then the system rules will be used instead.

</xs:documentation>

</xs:annotation>

</xs:attribute>

</xs:complexType>

</xs:element>


</xs:schema>