npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery.mobilephonenumber

v1.0.7

Published

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

Downloads

77

Readme

jQuery.mobilePhoneNumber Build Status

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.