Difference between revisions of "The phone number parser"

From Catglobe Wiki
Jump to: navigation, search
(jrfconvert import)
 
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:HelpBooks]]
+
  

 
  
===The phone number parser===
+
=== The phone number parser ===
  
The phone number parser makes it possible to decide which format phone numbers are legal for different countries.
+
The phone number parser makes it possible to decide which format phone numbers are legal for different countries.  
  
[[Image:5296.png|800px|LangCult5-5-1]]
+
[[Image:5296.png|800px|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.
+
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:
+
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 AreaCodeRegExp''  
  
''string AreaCodeDocumentation''
+
''string AreaCodeDocumentation''  
  
''string NumberRegExp''
+
''string NumberRegExp''  
  
''string NumberDocumentation''
+
''string NumberDocumentation''  
  
''Plus also a''
+
''Plus also a''  
  
''ReadOnlyCollection<string> Examples''
+
''ReadOnlyCollection<string> Examples''  
  
'''The following is the default example of how the XML is to be formatted with hints inside the XML.'''
+
<br> '''The following is the default example of how the XML is to be formatted with hints inside the XML.'''&nbsp;
[]^-{} 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.
+
<br>
  
&lt;/xs:documentation&gt;
+
&lt;?xml version="1.0" encoding="utf-8"&nbsp;?&gt;  
  
&lt;/xs:annotation&gt;
+
&lt;xs:schema id="Phonenumber"
  
&lt;xs:simpleType&gt;
+
targetNamespace="http://catglobe.com/Phonenumber.xsd"
  
&lt;xs:restriction base="xs:string"&gt;
+
elementFormDefault="qualified"  
  
&lt;xs:pattern value='[-\[\],0-9\\d\{\}]*'/&gt;
+
xmlns="http://catglobe.com/Phonenumber.xsd"
  
&lt;/xs:restriction&gt;
+
xmlns:mstns="http://catglobe.com/Phonenumber.xsd"
  
&lt;/xs:simpleType&gt;
+
xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;  
  
&lt;/xs:attribute&gt;
+
&lt;xs:complexType name="NumberNode"&gt;  
  
&lt;xs:attribute name="areadoc" type="xs:string" use="optional"/&gt;
+
&lt;xs:attribute name="area" use="optional"&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 us 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="areadoc" type="xs:string" use="optional"/&gt;  
  
&lt;xs:attribute name="numberdoc" type="xs:string" use="optional"/&gt;
+
&lt;xs:attribute name="number" use="required"&gt;  
  
&lt;/xs:complexType&gt;
+
&lt;xs:annotation&gt;  
  
&lt;xs:complexType name="PhoneNumNode"&gt;
+
&lt;xs:documentation&gt;  
  
&lt;xs:sequence&gt;
+
Must adhere to normal regular expressions for selecting digits. Only the chars []^-{} and 0 to 9 is accepted.
  
&lt;xs:element name="possiblenumber" type="NumberNode" minOccurs="1" maxOccurs="unbounded"/&gt;
+
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:sequence&gt;
+
&lt;/xs:documentation&gt;  
  
&lt;xs:attribute name="trunk" use="optional"&gt;
+
&lt;/xs:annotation&gt;  
  
&lt;xs:simpleType&gt;
+
&lt;xs:simpleType&gt;  
  
&lt;xs:restriction base="xs:positiveInteger"&gt;
+
&lt;xs:restriction base="xs:string"&gt;  
  
&lt;xs:pattern value='[0-9]'/&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="display" use="optional"&gt;
+
&lt;xs:attribute name="numberdoc" type="xs:string" use="optional"/&gt;  
  
&lt;xs:annotation&gt;
+
&lt;/xs:complexType&gt;  
  
&lt;xs:documentation&gt;
+
&lt;xs:complexType name="PhoneNumNode"&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.
+
&lt;xs:sequence&gt;
  
&lt;/xs:documentation&gt;
+
&lt;xs:element name="possiblenumber" type="NumberNode" minOccurs="1" maxOccurs="unbounded"/&gt;  
  
&lt;/xs:annotation&gt;
+
&lt;/xs:sequence&gt;  
  
&lt;xs:simpleType&gt;
+
&lt;xs:attribute name="trunk" use="optional"&gt;  
  
&lt;xs:restriction base="xs:string"&gt;
+
&lt;xs:simpleType&gt;  
  
&lt;xs:pattern value='[-0-9]*'/&gt;
+
&lt;xs:restriction base="xs:positiveInteger"&gt;  
  
&lt;/xs:restriction&gt;
+
&lt;xs:pattern value='[0-9]'/&gt;  
  
&lt;/xs:simpleType&gt;
+
&lt;/xs:restriction&gt;  
  
&lt;/xs:attribute&gt;
+
&lt;/xs:simpleType&gt;  
  
&lt;/xs:complexType&gt;
+
&lt;/xs:attribute&gt;  
  
&lt;xs:complexType name="CountryNode"&gt;
+
&lt;xs:attribute name="display" use="optional"&gt;  
  
&lt;xs:sequence&gt;
+
&lt;xs:annotation&gt;  
  
&lt;xs:element name="mobile" type="PhoneNumNode" maxOccurs="1"/&gt;
+
&lt;xs:documentation&gt;  
  
&lt;xs:element name="landline" type="PhoneNumNode" maxOccurs="1"/&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.
  
&lt;xs:element name="example" type="xs:string" minOccurs="0" maxOccurs="unbounded"/&gt;
+
&lt;/xs:documentation&gt;  
  
&lt;/xs:sequence&gt;
+
&lt;/xs:annotation&gt;  
  
&lt;xs:attribute name="countrycode" type="xs:ID" use="required"&gt;
+
&lt;xs:simpleType&gt;  
  
&lt;xs:annotation&gt;
+
&lt;xs:restriction base="xs:string"&gt;  
  
&lt;xs:documentation&gt;
+
&lt;xs:pattern value='[-0-9]*'/&gt;  
  
Prefix to call country. e.g. 45 for Denmark. Must be unique.
+
&lt;/xs:restriction&gt;
  
&lt;/xs:documentation&gt;
+
&lt;/xs:simpleType&gt;  
  
&lt;/xs:annotation&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:element name="Phonenumbers"&gt;
+
&lt;xs:sequence&gt;  
  
&lt;xs:annotation&gt;
+
&lt;xs:element name="mobile" type="PhoneNumNode" maxOccurs="1"/&gt;  
  
&lt;xs:documentation&gt;
+
&lt;xs:element name="landline" type="PhoneNumNode" maxOccurs="1"/&gt;  
  
&lt;![CDATA[
+
&lt;xs:element name="example" type="xs:string" minOccurs="0" maxOccurs="unbounded"/&gt;
  
&lt;Phonenumbers&gt;
+
&lt;/xs:sequence&gt;  
  
&lt;country countrycode="31"&gt;
+
&lt;xs:attribute name="countrycode" type="xs:ID" use="required"&gt;  
  
&lt;mobile trunk="0" display="3-3-3"&gt;
+
&lt;xs:annotation&gt;  
  
&lt;possiblenumber number="6\\d{8}" numberdoc="A 6 followed by 8 digits"/&gt;
+
&lt;xs:documentation&gt;  
  
&lt;/mobile&gt;
+
Prefix to call country. e.g. 45 for Denmark. Must be unique.
  
&lt;landline trunk="0" display="3-3-3"&gt;
+
&lt;/xs:documentation&gt;  
  
&lt;possiblenumber area="[1-5]0" areadoc="1 to 5 followed by a zero" number="\d{7}" numberdoc="7 digits"/&gt;
+
&lt;/xs:annotation&gt;  
  
...
+
&lt;/xs:attribute&gt;
  
&lt;/landline&gt;
+
&lt;/xs:complexType&gt;  
  
&lt;example&gt;blabla +31 666 666 666&lt;/example&gt;
+
<br>
  
&lt;example&gt;blablabla2&lt;/example&gt;
+
&lt;xs:element name="Phonenumbers"&gt;  
  
&lt;/country&gt;
+
&lt;xs:annotation&gt;  
  
...
+
&lt;xs:documentation&gt;
  
&lt;/Phonenumbers&gt;
+
&lt;![CDATA[
 +
 
 +
&lt;Phonenumbers&gt;
 +
 
 +
&lt;country countrycode="31"&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;/mobile&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;/landline&gt;
 +
 
 +
&lt;example&gt;blabla +31 666 666 666&lt;/example&gt;
 +
 
 +
&lt;example&gt;blablabla2&lt;/example&gt;
 +
 
 +
&lt;/country&gt;
 +
 
 +
...
 +
 
 +
&lt;/Phonenumbers&gt;  
  
 
]]&gt;
 
]]&gt;
  
&lt;/xs:documentation&gt;
+
&lt;/xs:documentation&gt;
 +
 
 +
&lt;/xs:annotation&gt;
 +
 
 +
&lt;xs:complexType&gt;
 +
 
 +
&lt;xs:sequence&gt;
 +
 
 +
&lt;xs:element name="country" type="CountryNode" minOccurs="1" maxOccurs="unbounded"/&gt;
 +
 
 +
&lt;/xs:sequence&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:complexType&gt;
+
If this date is before the system rules date, then the system rules will be used instead.
  
&lt;xs:sequence&gt;
+
&lt;/xs:documentation&gt;  
  
&lt;xs:element name="country" type="CountryNode" minOccurs="1" maxOccurs="unbounded"/&gt;
+
&lt;/xs:annotation&gt;  
  
&lt;/xs:sequence&gt;
+
&lt;/xs:attribute&gt;  
  
&lt;xs:attribute name="date" type="xs:date" use="required"&gt;
+
&lt;/xs:complexType&gt;  
  
&lt;xs:annotation&gt;
+
&lt;/xs:element&gt;  
  
&lt;xs:documentation&gt;
+
<br>
  
If this date is before the system rules date, then the system rules will be used instead.
+
&lt;/xs:schema&gt;<br>
  
&lt;/xs:documentation&gt;
+
<br>
  
&lt;/xs:annotation&gt;
+
<br>
  
&lt;/xs:attribute&gt;
+
<br>
  
&lt;/xs:complexType&gt;
+
<br>
  
&lt;/xs:element&gt;
+
&nbsp;&nbsp;  
  
&lt;/xs:schema&gt;
+
[[Category:Language_and_culture_settings]]
__NOTOC__
 
<!-- imported from file: 6937.htm-->
 

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>