The phone number parser

From Catglobe Wiki
Revision as of 10:08, 24 February 2012 by Cg pham (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



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>