• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

stripe-archive/jquery.mobilePhoneNumber: [DEPRECATED] A general purpose library ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

stripe-archive/jquery.mobilePhoneNumber

开源软件地址(OpenSource Url):

https://github.com/stripe-archive/jquery.mobilePhoneNumber

开源编程语言(OpenSource Language):

CoffeeScript 95.5%

开源软件介绍(OpenSource 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.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap