How to use the google-libphonenumber.PhoneNumberType function in google-libphonenumber

To help you get started, we’ve selected a few google-libphonenumber examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github anihalaney / rwa-trivia / projects / shared-library / src / lib / shared / mobile / component / countryList / phone-number-validation.provider.ts View on Github external
public isValidMobile(_phonenumber, country): any {
    try {
      const phoneUtil = phonenumbers.PhoneNumberUtil.getInstance();
      const phoneNumber = phoneUtil.parse(_phonenumber, country);
      const isValid = phoneUtil.isValidNumber(phoneNumber);
      // In some regions (e.g. the USA), it is impossible to distinguish between
      // fixed-line and mobile numbers by looking at the phone number itself
      const numberType = phoneUtil.getNumberType(phoneNumber);
      const isMobile = numberType === phonenumbers.PhoneNumberType.MOBILE ||
      numberType === phonenumbers.PhoneNumberType.FIXED_LINE_OR_MOBILE;

      if (isValid && isMobile) { return true; }
    } catch (e) {
      console.error(e);
    }
    return false;
  }
}
github anihalaney / rwa-trivia / projects / shared-library / src / lib / shared / mobile / component / countryList / phone-number-validation.provider.ts View on Github external
public isValidMobile(_phonenumber, country): any {
    try {
      const phoneUtil = phonenumbers.PhoneNumberUtil.getInstance();
      const phoneNumber = phoneUtil.parse(_phonenumber, country);
      const isValid = phoneUtil.isValidNumber(phoneNumber);
      // In some regions (e.g. the USA), it is impossible to distinguish between
      // fixed-line and mobile numbers by looking at the phone number itself
      const numberType = phoneUtil.getNumberType(phoneNumber);
      const isMobile = numberType === phonenumbers.PhoneNumberType.MOBILE ||
      numberType === phonenumbers.PhoneNumberType.FIXED_LINE_OR_MOBILE;

      if (isValid && isMobile) { return true; }
    } catch (e) {
      console.error(e);
    }
    return false;
  }
}
github ionicthemes / ionic-forms-and-validations / src / app / form / country-phone.model.ts View on Github external
constructor (iso: string, name: string) {
    this.iso = iso;
    this.name = name;

    let phoneUtil = libphonenumber.PhoneNumberUtil.getInstance(),
        PNF = libphonenumber.PhoneNumberFormat,
        PNT = libphonenumber.PhoneNumberType,
        country_example_number = phoneUtil.getExampleNumberForType(this.iso, PNT.MOBILE),
        // We need to define what kind of country phone number type we are going to use as a mask.
        // You can choose between many types including:
        //    - FIXED_LINE
        //    - MOBILE
        //    - For more types please refer to google libphonenumber repo (https://github.com/googlei18n/libphonenumber/blob/f9e9424769964ce1970c6ed2bd60b25b976dfe6f/javascript/i18n/phonenumbers/phonenumberutil.js#L913)
        example_number_formatted = phoneUtil.format(country_example_number, PNF.NATIONAL);
        // We need to define how are we going to format the phone number
        // You can choose between many formats including:
        //    - NATIONAL
        //    - INTERNATIONAL
        //    - E164
        //    - RFC3966

    this.sample_phone = example_number_formatted;
    this.code = "+" + country_example_number.getCountryCode();
github ionicthemes / ionic-forms-and-validations / ionic-3 / src / pages / form / form.model.ts View on Github external
constructor (iso: string, name: string) {
    this.iso = iso;
    this.name = name;

    let phoneUtil = libphonenumber.PhoneNumberUtil.getInstance(),
        PNF = libphonenumber.PhoneNumberFormat,
        PNT = libphonenumber.PhoneNumberType,
        country_example_number = phoneUtil.getExampleNumberForType(this.iso, PNT.MOBILE),
        // We need to define what kind of country phone number type we are going to use as a mask.
        // You can choose between many types including:
        //    - FIXED_LINE
        //    - MOBILE
        //    - For more types please refer to google libphonenumber repo (https://github.com/googlei18n/libphonenumber/blob/f9e9424769964ce1970c6ed2bd60b25b976dfe6f/javascript/i18n/phonenumbers/phonenumberutil.js#L913)
        example_number_formatted = phoneUtil.format(country_example_number, PNF.NATIONAL);
        // We need to define how are we going to format the phone number
        // You can choose between many formats including:
        //    - NATIONAL
        //    - INTERNATIONAL
        //    - E164
        //    - RFC3966

    this.sample_phone = example_number_formatted;
    this.code = "+" + country_example_number.getCountryCode();
github dial-once / node-phone-utils / lib / validators / phone-number-validator.js View on Github external
/**
 * A phone number utilities validator module based on google phone number lib!
 * @module phone-number-validator
 * @private
 */

var InputValidator = require('./input-validator');
var getLogger = require('../logging/logger-options-parser').getLoggerFromOptions;
var PNExtractor = require('../extractors/phone-number-extractor');
var libPhoneNumber = require('google-libphonenumber');
var phoneUtil = libPhoneNumber.PhoneNumberUtil.getInstance();
var PhoneNumberType = libPhoneNumber.PhoneNumberType;

/**
 * @private
 * @type {logFunction}
 */
var loggingFunc = require('../logging/logger-message-formatter').getLoggerMessageFunc('phone-number-validator');

/**
 * Phone number validator utility class
 * @private
 * @param logger non optional (or facaded) logger
 * @returns {{isValid: isValid, isMobile: isMobile}}
 * @constructor
 */
function PNValidator(logger) {
  var pnExtractor = PNExtractor.createInstance({logger: logger});
github dial-once / node-phone-utils / lib / extractors / phone-number-extractor.js View on Github external
/**
 * A phone number utilities extractor module based on google phone number lib!
 * @module phone-number-extractor
 * @private
 */

var _ = require('lodash');
var getLogger = require('../logging/logger-options-parser').getLoggerFromOptions;
var libPhoneNumber = require('google-libphonenumber');
var phoneUtil = libPhoneNumber.PhoneNumberUtil.getInstance();
var PhoneNumberType = libPhoneNumber.PhoneNumberType;
var loggingFunc = require('../logging/logger-message-formatter').getLoggerMessageFunc('phone-number-extractor');

/**
 * Phone number extractor class
 * @private
 * @param logger - a non optional (or facaded) logger;
 * @returns {{PhoneNumberType: *, getGooglePhoneNumber: getGooglePhoneNumber, getType: getType, getCountryCode: getCountryCode}}
 * @constructor
 */
var PNExtractor = function PNExtractor(logger) {

  return {

    /**
     * Gets a google phone number type
     */