Coder Social home page Coder Social logo

incorrect normalization about phony HOT 5 CLOSED

floere avatar floere commented on August 18, 2024
incorrect normalization

from phony.

Comments (5)

floere avatar floere commented on August 18, 2024

Thanks for the issue. However, for this to be a useful issue entry, it needs more information:

As a bare minimum: What was your expectation? What are your assumptions underlying that expectation?

from phony.

xn avatar xn commented on August 18, 2024

I'm in the US, we would expect that number to be "6505615158" a three digit area code, followed by a three digit exchange and then a four digit ID.

from phony.

floere avatar floere commented on August 18, 2024

Hi Christian,

Phony is an international phone number library (see README). When it looks at your number, it sees a number from Singapore (since it starts with 65). It then correctly concludes that the 0 is erroneous and removes it.

It has no possibility of magically deducing that your number is an incorrect US E164 number and auto correcting, adding a US country code of 1. You need to tell it that it is looking at a US number.

So with the correct country code added:

Phony.normalize("1 650 561 5158") # => "16505615158"
Phony.formatted("16505615158") # => "+1 650 561 5158"

I hope that helps. Cheers!

from phony.

xn avatar xn commented on August 18, 2024

Thanks. I appreciate your time.

from phony.

floere avatar floere commented on August 18, 2024

My pleasure. One idea is to simply add a 1 if there isn't one at the beginning already if you know you only have US numbers:

number = Phony.normalize(number =~ /\A1/ ? number : "1#{number}")

from phony.

Related Issues (20)

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.