GithubHelp home page GithubHelp logo

isabella232 / jquery.mobilephonenumber Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stripe-archive/jquery.mobilephonenumber

0.0 0.0 0.0 100 KB

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

License: MIT License

CoffeeScript 95.48% HTML 4.52%

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

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.