libphonenumber standalone (without masses of google dependencies)? Alternate lib?

前端 未结 4 1573
生来不讨喜
生来不讨喜 2020-12-23 14:02

I am looking at using http://code.google.com/p/libphonenumber/ for a well-established project. Today the project does not use Google\'s libraries for JavaScript, favoring jQ

相关标签:
4条回答
  • 2020-12-23 14:09

    I've got a custom build (currently 220KB) that I use for my International Telephone Input plugin, with plenty of helper functions exposed. Read the source for details.

    0 讨论(0)
  • 2020-12-23 14:09

    Here are two implementations of Google libphonenumber in JavaScript that have zero dependencies and are implemented in a single file. I've used Nathan Hammond's version without issue but it is not on NPM. Rui Marinho's version is on NPM.

    • https://github.com/nathanhammond/libphonenumber
    • https://github.com/ruimarinho/google-libphonenumber
    0 讨论(0)
  • 2020-12-23 14:11

    You can also use my lib. https://github.com/Gilshallem/phoneparser

    Its only got one method but you can do a lot with it

    parsePhone("12025550104");
    result: { countryCode:1, areaCode:202, number:5550104, countryISOCode:"US" }
    
    0 讨论(0)
  • 2020-12-23 14:24

    I just spent 2 days figuring this out. For now, anyway, you can download a minified version of libphonenumber-js from here

    drop it in place, with the usual

    <script type="text/javascript" language="javascript" src="/static/js/libphonenumber-js.min.js"></script>
    

    and get busy coding!

    <script>
        $(".phone-format").keyup(function () {
                var val_old = $(this).val();
                var newString = new libphonenumber.AsYouType('US').input(val_old);
                $(this).focus().val('').val(newString);
        });
    </script>
    
    0 讨论(0)
提交回复
热议问题