Git Product home page Git Product logo

jquery.mobilephonenumber's Introduction

Project status

This project is deprecated.

We will patch jquery.mobilePhoneNumber for critical security issues, but won't be adding any new features.

jQuery.mobilePhoneNumber Build Status CDNJS

A general purpose library for validating and formatting mobile phone numbers.

$("input.phone-num").mobilePhoneNumber();

You can bind to an event when the user changes the country of the phone number:

$("input.phone-num").bind("country.mobilePhoneNumber", function(e, country) {
  console.log("The new country code:", country);
});

You can find a demo here.

Dependencies:

API

$.fn.mobilePhoneNumber([options])

Enables phone number formatting.

Options:

  • defaultPrefix: allows the user to type a phone number without the prefix for this specific value.

Example:

$("input.phone-num").mobilePhoneNumber({
  defaultPrefix: "+1"
});

$.fn.mobilePhoneNumber('val')

Returns the phone number value with prefix, but without other formatting.

Example:

$("input.phone-num").val(); //=> '+1 (415) 123-5554'
$("input.phone-num").mobilePhoneNumber("val"); //=> '+14151235554'

$.fn.mobilePhoneNumber('validate')

Returns whether the phone number is valid.

Note: this implementation is very naive; it only validates that the phone number is longer than its prefix.

Example:

$("input.phone-num").val(); //=> '+1 (415) 123-5554'
$("input.phone-num").mobilePhoneNumber("validate"); //=> true

$("input.phone-num").val(); //=> '+43'
$("input.phone-num").mobilePhoneNumber("validate"); //=> false

$.fn.mobilePhoneNumber('country')

Returns the two-letter country code of the phone number.

Example:

$("input.phone-num").val(); //=> '+32 495 12 34 56'
$("input.phone-num").mobilePhoneNumber("country"); //=> 'BE'

$.fn.mobilePhoneNumber('prefix')

Returns the prefix of the phone number.

Example:

$("input.phone-num").val(); //=> '+32 495 12 34 56'
$("input.phone-num").mobilePhoneNumber("prefix"); //=> '+32'

$.formatMobilePhoneNumber(phone)

Returns the formatted phone number.

Example:

$.formatMobilePhoneNumber("14151235554"); //=> '+1 (415) 123-5554'

Events

country.mobilePhoneNumber

Triggered when the country has changed.

Example:

$("input.phone-num").bind("country.mobilePhoneNumber", function(e, country) {
  console.log("The new country code:", country);
});

// Simulate user input
$("input.phone-num")
  .val("+32495123456")
  .keyup();
//=> The new country code: BE

Building

Run cake build

Running tests

Run cake test

Mobile recommendations

We recommend you set the pattern, type, and x-autocompletetype attributes, which will trigger autocompletion and a numeric keypad to display on touch devices:

<input class="phone-num" type="tel" pattern="\d*" x-autocompletetype="tel" />

You may have to turn off HTML5 validation (using the novalidate form attribute) when using this pattern, since it won't permit spaces and other characters that appear in the formatted version of the phone number.

jquery.mobilephonenumber's People

Contributors

christopher-stripe avatar coliff avatar dependabot[bot] avatar dougshamoo avatar jamesreggio avatar jenan-stripe avatar jez avatar kjc-stripe avatar koven-stripe avatar kyleconroy avatar michaelvillar avatar mv-stripe avatar niftylettuce avatar nolsherry avatar rlk-stripe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery.mobilephonenumber's Issues

Select All behavior

In the demo, selecting all results in numbers inserted at the front instead of replacing the whole thing like normal text fields.

Handle trunk_prefixes

As written on Wikipedia, trunk prefixes are removed if we use the country code, otherwise conserved.

For example, for a french number I will wether write: 06 xx xx xx xx or +33 6 xx xx xx xx. Right, now if I set allowPhoneWithoutPrefix to +33 for example, it'll format as 0 6x xx xx xx xx which is not what we expect.

Can not delete space in mobile phones

Hi,

I use this script on my project. Thank you for your all, it is really cool.

I had realized a problem the other day, I can not delete space chars on my mobile devices, once I wrote down the formated phone number.

For instance, I started to write "905", it converts it "+90 5", but after I want to correct my "90" with "1", I can only delete 5, not the space char (since it formatted my numbers as phone number it inserts a space). So I can not change my international country code.

Or when I type "905551" it converts it "+90 555 1", and I can only delete "1" not the space char or "555" chars.

It works on web browsers without any problem, but on my mobile devices, it cause the problem I describe above. Is there any solution?

I tested both with Android 5.0.1 and iPhone 6s.

Thank you from now :)

Brazilian mobile phone numbers

In Brazil we had changes from Anatal, now mobile phone numbers have the number 9 before the first digit of mobile phones, but this is no on every city. Only some of brazilian states have this change, and only mobile phone numbers. The landline telephone numbers of all states still with 8 digits .
I dont have idea of what to do about that .
Anatal sux. Dilma sux .

mobile vs land line?

Is there any difference between mobile numbers and non land line numbers or is it simply the name that was picked out for the application.

Testing and License

I've been going through and making sure that our open source projects are all open source best citizens. Could you make sure to add a LICENSE file before making this public? Most repositories are MIT.

Also, a small test suite would be great. See https://github.com/stripe/jquery.payment for our Travis CI setup. Let me know if you have any questions!

Security issues NPM

I installed this cool package , ran npm audit and this is the result:

  Moderate        Prototype Pollution                                           
                                                                                
  Package         jquery                                                        
                                                                                
  Patched in      >=3.4.0                                                       
                                                                                
  Dependency of   jquery.mobilephonenumber [dev]                                
                                                                                
  Path            jquery.mobilephonenumber > jquery                             
                                                                                
  More info       https://npmjs.com/advisories/796                              
                                                                                
                                                                                
  High            Cross-Site Scripting (XSS)                                    
                                                                                
  Package         jquery                                                        
                                                                                
  Patched in      >=3.0.0                                                       
                                                                                
  Dependency of   jquery.mobilephonenumber [dev]                                
                                                                                
  Path            jquery.mobilephonenumber > jquery                             
                                                                                
  More info       https://npmjs.com/advisories/328           

my package.json file:

...
        "jquery": "^3.4.1",
        "jquery.mobilephonenumber": "^1.0.7",
...

Any idea how this could be fixed?

jquery change event

seems like the standard jquery 'change' event is not firing
I created a simple form & jquery code as per below.
the change function gets executed for for name field, but not for the phone.
Am I missing something?

$("#name").change(function(){
debugger;
console.log('NAME-CHANGE: VAL:',$("#name").val());
});

$("#phone").change(function(){
    debugger;
    $("#phone").val($.formatMobilePhoneNumber($("#phone").mobilePhoneNumber('val')))
    console.log('PHONE-CHANGE: VAL:',$("#phone").val());
});

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.