Giter VIP home page Giter VIP logo

phonenum's Introduction

phonenum

A delphi library for handling mobile phone numbers based on the ITU REC.E212 standard.

Nuances

  • Right now this library only supports mobile phone numbers, not fixed ones which can be smaller and out of standard compared to the mobile number standard REC E.212.

  • The RECE.212 MNC (mobile network code), the second number after the country code number, is assumed to be the carrier code, the standard mentions that the network code is defined by the country itself, and not the ITU. So for mostry countries, MNC is the carrier code and here assumed as such.

Table of contents

Install

Using boss

Just use the following command:

$ boss install github.com/Joao-Peterson/phonenum

If asked for permission, you can login with your github credentials. (must be done in powershell or cmd with administrator mode)

$ boss login
> Url to login (ex: github.com): github.com
> Use SSH(y or n):
> n
> Username: your_username
> Password: your_password

Note: ssh isn't supported, hence the 'n' for not using ssh. See this issue with boss: HashLoad/boss#52. Check it out because it may be working in the future.

Usage

Here a TLDR sample usage for a sample brazillian mobile phone number, where a phone is parsed and created, printed using the brazillian and internacional representation and the country and DDD names are printed, this provides code checking for a number, checking if the country code exists and the DDD brazillian code exists also.

procedure handlePhone();
begin
    var p: TphoneNum; 

    try
        p := TphoneNum.CreateFromBrazil('49 5769-8674');
    except
        on E: Exception do raise;
    end;

    WriteLn(p.brazilNumber);
    // 49 95769-8674
    // note that for CreateFromBrazil, numbers without a extra 9 will be corrected

    WriteLn(p.internacionalNumber);
    // 55 49 957698674

    // error will be raised if country or brazil DDD region codes are invalid
    try
        WriteLn(p.countryName);
        // Brazil

        WriteLn(p.dddRegion);
        // Santa Catarina
    except
        on E: Exception do raise;
    end;
end;

Standards

Representation

This library uses the ITU E.212 IMSI stardard for intrnacional mobile phone numbers representation.

Source: ITU.

And furthermore, the MSIN is broken down into two parts in the code, wich are combined when using the internacional representation but separeted while using the common brazillian representation.

Country and MNC/DDD Validation

Country code validation and naming are based on the official ITU spec and so is the MVC/DDD regional code validation and naming for brazilian regions. So far only 3 digit country codes are supported.

Tables for the codes and names for coutries/DDD's are in:

Files and sources

All sources, standards and tables are in the docs/ folder.

Tests

Tests are done by the Utests.pas program using DunitX. Just compile the test.dproj project and execute the tests.

Error handling

This library raises a Ephone exception type on errors, make sure to wrap things around with a try-except block.

TODO

  • Validação de numero mobile x fixo
  • Melhorar a estrutura das lista de ddd e country code
  • Separar funções brasileiras em uma classe separada

phonenum's People

Contributors

joao-peterson avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.