插件 jQuery.mobilephonenumber 中文API文档

🌙
手机阅读
本文目录结构

插件 jQuery.mobilephonenumber 中文API文档 https://github.com/stripe/jquery.mobilePhoneNumber

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.

AXIHE / 精选资源

浏览全部教程

面试题

学习网站

前端培训
自己甄别

前端书籍

关于朱安邦

我叫 朱安邦,阿西河的站长,在杭州。

以前是一名平面设计师,后来开始接接触前端开发,主要研究前端技术中的JS方向。

业余时间我喜欢分享和交流自己的技术,欢迎大家关注我的 Bilibili

关注我: Github / 知乎

于2021年离开前端领域,目前重心放在研究区块链上面了

我叫朱安邦,阿西河的站长

目前在杭州从事区块链周边的开发工作,机械专业,以前从事平面设计工作。

2014年底脱产在老家自学6个月的前端技术,自学期间几乎从未出过家门,最终找到了满意的前端工作。更多>

于2021年离开前端领域,目前从事区块链方面工作了