Difference between revisions of "The phone number parser"

From Catglobe Wiki
Jump to: navigation, search
Line 1: Line 1:
[[Category:Language_and_culture_settings]]
+


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

Revision as of 09:09, 6 January 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. 


</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>

][Image:5296.png|800px|LangCult5-5-1]]>

</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>