/meteor-libphonenumber

(Meteor wrapper) Javascript library for parsing, formatting, storing and validating international phone numbers

Primary LanguageJavaScript

meteor-libphonenumber

Meteor wrapper of google-libphonenuber, itself a wrapper of libphonenumber.

Javascript library for parsing, formatting, storing and validating international phone numbers

Exports LibPhoneNumber on server only.

####Example usage:

if (Meteor.isServer()) {
  var util = LibPhoneNumber.phoneUtil;
  var format = LibPhoneNumber.PhoneNumberFormat;
  var types = LibPhoneNumber.PhoneNumberType;

  function getKey (obj, val) {
    for (var prop in obj) {
      if (obj.hasOwnProperty(prop))
        if (obj[prop] === val)
          return prop;
    }
  };

  function parsePhone (opts) {
    var parsedNumber = util.parse(opts.phone, opts.country || "US");
    var type = getKey(types, util.getNumberType(parsedNumber));

   return {
      phone   : util.format(parsedNumber, format.E164),
      isValid : util.isValidNumber(parsedNumber),
      type    : type
    };
  }
}