mobi / telephone_number Goto Github PK
View Code? Open in Web Editor NEWPhone number validation for Ruby
License: MIT License
Phone number validation for Ruby
License: MIT License
timezone
Returns the time zone of the number.
phone_object.location ==> "America/New_York"
location in place of timezone
23776671338
Country Code ---- 237
Country --- Cameroon
TelephoneNumber.invalid?('76671338', 'CM', [:mobile, :fixed_line])
giving true for this
559282828685
Country Code -- 55
Country -- BR
TelephoneNumber.invalid?('9282828685', 'BR', [:mobile, :fixed_line])
But these two numbers i have received from whatsapp meta webhook
[{"id"=>"102901402735930", "changes"=>[{"value"=>{"messaging_product"=>"whatsapp", "metadata"=>{"display_phone_number"=>"918069195810", "phone_number_id"=>"109626598719981"}, "contacts"=>[{"profile"=>{"name"=>"A. Banderas"}, "wa_id"=>"23776671338"}], "messages"=>[{"context"=>{"from"=>"918069195810", "id"=>"wamid.HBgLMjM3NzY2NzEzMzgVAgARGBI0NDNDNTk2QjI3RDk5MDc2RTAA"}, "from"=>"23776671338", "id"=>"wamid.HBgLMjM3NzY2NzEzMzgVAgASGBQzQUQ3QkU0NTg2RDQ1QTZDNERERQA=", "timestamp"=>"1681753310", "type"=>"interactive", "interactive"=>{"type"=>"list_reply", "list_reply"=>{"id"=>"2", "title"=>"CNSGH To CMDLA", "description"=>"Shanghai (CNSGH), Shanghai, Ch.. To Douala (CMDLA), Douala, Cameroon"}}}]}, "field"=>"messages"}]}]
[{"id"=>"102901402735930", "changes"=>[{"value"=>{"messaging_product"=>"whatsapp", "metadata"=>{"display_phone_number"=>"918069195810", "phone_number_id"=>"109626598719981"}, "contacts"=>[{"profile"=>{"name"=>"Daniella Martins"}, "wa_id"=>"559282828685"}], "messages"=>[{"context"=>{"from"=>"918069195810", "id"=>"wamid.HBgMNTU5MjgyODI4Njg1FQIAERgSRTVBMTU1MzQyRjI1OTJFNkZCAA=="}, "from"=>"559282828685", "id"=>"wamid.HBgMNTU5MjgyODI4Njg1FQIAEhgUM0FCN0QzNUNCQ0E1NTk3NDEzQTEA", "timestamp"=>"1681183686", "type"=>"interactive", "interactive"=>{"type"=>"button_reply", "button_reply"=>{"id"=>"1", "title"=>"Make a new search"}}}]}, "field"=>"messages"}]}]
If these two are verified from whatsapp , so i should also be able to save these numbers in my database, but the gem gives invalid for both
they are started issuing phone numbers with area code 464.
plz add this area code in the list
How can I get the national code of a phone and just the number without the national code?
irb(main):064> result = TelephoneNumber.parse("+5555999999999")
=>
#<TelephoneNumber::Number:0x000000013d4d5d30
...
irb(main):065> result.international_number
=> "+55 55 99999-9999"
irb(main):066> result.national_number
=> "(55) 99999-9999"
irb(main):067> result.national_area_code
(irb):67:in `<main>': undefined method `national_area_code' for an instance of TelephoneNumber::Number (NoMethodError)
given phone_object = TelephoneNumber.parse("3175082237", :us)
,
phone_object.country #=> NoMethodError
phone_object.country_data #=> NoMethodError
The data is still accessible but must be called via:
phone_object.phone_data.country_data[:id] #=> "US"
phone_object.phone_data.country_data #=> {Hash}
Could you please update either the code or the documentation?
Gem Version: 1.4.9 and 1.4.11
Ruby Version: 2.6.6
Example (last 4 digits anonymized):
irb(main):006:0> TelephoneNumber.parse('+4917880xxxx').e164_number
=> "+494917880"
You can see that the input number starts with 49
, but the e164 number starts with 4949
.
Our lockfile includes 1.4.17, but today I was no longer able to bundle. Took a look at Rubygems and saw the jump from .16 to .18, so also checked the CHANGELOG and see the same thing. Did something happen? Any information would be appreciated, mostly so we know if there's something to worry about.
Hi,
The isValid method simply returns a boolean without an error message regarding the failure cause. Is there anyway we can hook into the validation message as it will be helpful to the end user?
Regards,
Deepak
Hi
I am doing something wrong?
Im trying to validate a phone number and it always says that it is valid but to me it should say that it is not:
irb(main):016:0> TelephoneNumber.valid?("+573053036788-qwdqwdqwd-qwdqwd-asd")
=> true
irb(main):017:0> TelephoneNumber.valid?("+573053036788-qwdqwdqwd-qwdqwd-as(d")
=> true
irb(main):018:0> TelephoneNumber.valid?("+573053036788-qwdqwdqwd-)qwdqwd-as(d")
=> true
TelephoneNumber.parse('+543801234567', :ar).valid?
=> false
Tested with version 1.4.9 and 1.4.8
Numberjacki.io says this is a valid number..
Ruby version: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
OS: OSX
Here's the stack trace of the error I'm seeing:
NameError: uninitialized constant TelephoneNumber::Number::Forwardable
from /Users/jared.pavan/.rvm/gems/ruby-2.3.1/gems/telephone_number-1.2.0/lib/telephone_number/number.rb:3:in `<class:Number>'
from /Users/jared.pavan/.rvm/gems/ruby-2.3.1/gems/telephone_number-1.2.0/lib/telephone_number/number.rb:2:in `<module:TelephoneNumber>'
from /Users/jared.pavan/.rvm/gems/ruby-2.3.1/gems/telephone_number-1.2.0/lib/telephone_number/number.rb:1:in `<top (required)>'
from /Users/jared.pavan/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/jared.pavan/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/jared.pavan/.rvm/gems/ruby-2.3.1/gems/telephone_number-1.2.0/lib/telephone_number/class_methods.rb:11:in `parse'
from /Users/jared.pavan/.rvm/gems/ruby-2.3.1/gems/telephone_number-1.2.0/lib/telephone_number/class_methods.rb:15:in `valid?'
from (irb):2
from /Users/jared.pavan/.rvm/rubies/ruby-2.3.1/bin/irb:11:in `<main>'```
I am trying the following code, but it is returning invalid for me, 945
is a recently area code added to Dallas, do we have any prevision about when it will be added to this gem?
TelephoneNumber.parse('9452642426').valid?
=> false
TelephoneNumber.parse('+12024561111')
is a valid way of parsing phone numbers, and is not documented.
irb(main):022> TelephoneNumber.valid?('+85290191054')
=> true
irb(main):023> TelephoneNumber.valid?('+85290191054', [:mobile])
=> false
irb(main):024> TelephoneNumber.valid?('+85290191054', 'HK', [:mobile])
=> true
Is this by design? ๐ค
My scenario:
So, I'm using the validator like so:
validates :mobile_number, telephone_number: { country: proc { |record| TelephoneNumber.parse(record.mobile_number).country&.country_id }, types: [:mobile] }
This works fine, but would it be possible to auto-detect like i do here, but without specifying the country option, or another attribute like detect_country: true
?
Thanks :)
No sure what i'm doing wrong but seeing:
ArgumentError (Unknown validator: 'TypesValidator')
with the following line:
validates :phone, telephone_number: :us, types: [:fixed_line, :mobile]
Version: telephone_number (1.3.1)
The validation of phone numbers won't work for the new format in Ivory Cost. Phone numbers will move from 8 to 10 digits.
Ref: https://www.itu.int/oth/T0202000034/en
I believe this phone number is valid but this Gem claims not.
This Python port, https://github.com/daviddrysdale/python-phonenumbers, parses the number as valid as does the on-line Java implementation at http://libphonenumber.appspot.com/
Note that this is not the only number that other implementations accept but this Gem does not.
The validations in this gem are great! I'm wondering if it's possible to get a user-friendly format string out somehow that is suitable for displaying to end users, in a form input placeholder or hint, for example? That would really make it shine.
Example for the US (United States):
"(xxx) xxx-xxxx"
Something like that would be awesome, because then we could pipe it into a client-side Javascript library to validate the format on the client-side as well, and give the user hints about the acceptable format for their country.
Thanks for a great gem!
Hello, tried parsing the complete indian mobile number along with country code, but he object's location method returns nothing.
Please let me know, if I am missing something
this returns nothing, only empty line
require 'telephone_number'
mobile = TelephoneNumber.parse("+917503907302")
puts mobile.location
Do you have any script for Ruby Programming like this:
Enter username facebook or url facebook of person: etc
FULL NAME: JOHN DOE
PHONE NUMBER: 200202022
LAT.
LONG.....
Could you add please the numbers from Sri Lanka and Vietnam? Because at the moment it seems to not work.
Example:
pry(main)> TelephoneNumber.parse("+84283456789").valid? => false
pry(main)> TelephoneNumber.parse("+84283456789").country.country_id NoMethodError: undefined method 'country_id' for nil:NilClass
Hi,
We are working with Australia, and inside libphonenumber (libphonenumber.appspot.com) we see that this australian number is mobile - 0460 441 216
While on your demo is seems to be invalid
This is causing our product to not support these numbers
phone_number = '(787) 402-9077'
TelephoneNumber.parse(phone_number, :us).valid?
=> false
But provided phone number is correct. Are there any new formats needs to be added in this gem?
When use TelephoneNumber.parse("621791146")
the phone number is identified as an Indonesian number by default
But in this case, it's a Luxembourg number
Here, it confuses the Indonesian country code with a number base valid in 62 Luxembourg.
TelephoneNumber.parse("621791146")
#<TelephoneNumber::Number:0x00005555837144f8 @original_number="621791146", @country=#<TelephoneNumber::Country:0x00005555842b8ef8 @country_code="62", @country_id="ID", ...
TelephoneNumber.parse("621791146").e164_number
# "+62621791146"
TelephoneNumber.parse("621791146", :LU).e164_number
# "+352621791146"
Hello, is it possible to add this country ID?
Below are the errors we receive when a user selects this country:
NoMethodError
undefined method `country_id' for nil:NilClass
Hi
I find that the releases tag shows which versions exists but I can't find a place to show what changed when, so I can know why I should update or not.
Having a file CHANGELOG.md
is a good way or putting the changes on relases/ on github is another one.
What do you think?
I have installed gem in ruby on rails project, its' showing +91 1231 231 1
as valid number but it's not a valid number.
Example:
TelephoneNumber.parse('+91 1231 231 1').valid? # coming true
TelephoneNumber.valid?('+91 1231 231 1') # coming true
TelephoneNumber.valid?('+91 1231 231 1', :IN) # coming true
I have tried in demo website http://numberjack.io/ it's showing invalid to this above number.
We have users who try to use our app who have virgin islands phone numbers or canadian phone numbers... We currently validate against US, but it would be nice to be able too validate against any number with a +1 country code
libphonenumber-js allow this number to be valid in Pakistan but telephone_number does not allow it. is telephone_number is not using method provided by libphonenumber-js?
Hi,
After the update to 1.4.0, I'm getting this error:
NoMethodError: undefined method match?' for "11986865178":String Did you mean? match from telephone_number/parser.rb:34:in
block in validate'
from telephone_number/parser.rb:33:in select' from telephone_number/parser.rb:33:in
validate'
from telephone_number/parser.rb:12:in valid_types' from telephone_number/parser.rb:16:in
valid?'
from forwardable.rb:202:in valid?' from telephone_number/formatter.rb:9:in
initialize'
from telephone_number/number.rb:14:in new' from telephone_number/number.rb:14:in
initialize'
from telephone_number/class_methods.rb:11:in new' from telephone_number/class_methods.rb:11:in
parse'
from telephone_number/class_methods.rb:15:in valid?' from telephone_number/class_methods.rb:19:in
invalid?'
from active_model/telephone_number_validator.rb:5:in validate_each' from active_model/validator.rb:167:in
block in validate'
from active_model/validator.rb:164:in each' from active_model/validator.rb:164:in
validate'
Regards,
I would love to use this gem as it seems to solve issue both Phony and GlobalPhone have, but ...
We already have a class named TelephoneNumber in our application, that coincidentally is a telephone number
Using the constant TelephoneNumber, without any namespacing, is likely to not only clash with our application, but with others too
On a more philosophical level, you are using a constant that is a noun as opposed to a name that represents a library for number parsing/formatting
Any chance this can be namespaced without us having to fork and namespace it ourselves? (which will make updates impossibly hard)
Hello i m new at this and ruby , please can you explain how to run? after gem install telephone_number what should i do to run?
And how can i make csv upload and get generated csv ? Thnx
Is it possible to validate active model without specify a country ?
ex:
validates :phone_number, presence: true, telephone_number: true
Thank you
I'm expecting a well-formed foreign number, even if there is a country bias, to be understood correctly. For instance, if I dial +41446681800
in Canada, I need to understand that this is a valid Swiss number (+41
).
n = TelephoneNumber.parse("+41446681800", :ca)
n.valid?
# false
# Expected: true
n.country.country_id
# "CA"
# Expected: "CH"
n.e164_number
# "41446681800"
# Expected: "+41446681800"
Using this gem, I will get that a number is a mobile
Whereas if I take from the source (https://libphonenumber.appspot.com/phonenumberparser?number=62818731241&country=ID)
will be a fixed line result (fixed line result should be the correct one)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.