How to use the google-libphonenumber.PhoneNumberUtil 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 ionicthemes / ionic-forms-and-validations / ionic-3 / src / validators / phone.validator.ts View on Github external
return (phoneControl: AbstractControl): {[key: string]: boolean} => {
      if (!subscribe) {
        subscribe = true;
        countryControl.valueChanges.subscribe(() => {
          phoneControl.updateValueAndValidity();
        });
      }

      if(phoneControl.value !== ""){
        try{
          const phoneUtil = libphonenumber.PhoneNumberUtil.getInstance();
          let phoneNumber = "" + phoneControl.value + "",
              region = countryControl.value.iso,
              number = phoneUtil.parse(phoneNumber, region),
              isValidNumber = phoneUtil.isValidNumber(number);

          if(isValidNumber){
            return null;
          }
        }catch(e){
          // console.log(e);
          return {
            validCountryPhone: true
          };
        }

        return {
github communitybridge / easycla / frontend-project-management-console / src / ionic / validators / phonenumber.ts View on Github external
// Copyright The Linux Foundation and each contributor to CommunityBridge.
// SPDX-License-Identifier: MIT

import { FormControl } from '@angular/forms';
declare var require: any;
var phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();

export class PhoneNumberValidator {

    static isValid(control: FormControl): any {

      let number = control.value;
      let phoneProto;
      if(number == null || number == '') {
        return null;
      }

      let countryCode = 'US';
      if(number.charAt(0)==='+') {
        countryCode = 'ZZ';
      }
github communitybridge / easycla / cla-frontend-contributor-console / src / ionic / validators / phonenumber.ts View on Github external
// Copyright The Linux Foundation and each contributor to CommunityBridge.
// SPDX-License-Identifier: MIT

import { FormControl } from '@angular/forms';
declare var require: any;
var phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();

export class PhoneNumberValidator {
  static isValid(control: FormControl): any {
    let number = control.value;
    let phoneProto;
    if (number == null) {
      return {
        empty: true
      };
    }

    let countryCode = 'US';
    if (number.charAt(0) === '+') {
      countryCode = 'ZZ';
    }
github blockchain / bc-phone-number / src / js / libphonenumber.js View on Github external
function isValidNumber(number, countryCode) {
  try {
    var phoneUtil = libphonenumber.PhoneNumberUtil.getInstance();
    var numberObj = phoneUtil.parseAndKeepRawInput(number, countryCode);
    return phoneUtil.isValidNumber(numberObj);
  } catch (e) {
    return false;
  }
}
github keybase / client / shared / util / phone-numbers / index.tsx View on Github external
import {isMobile} from '../../constants/platform'
import libphonenumber from 'google-libphonenumber'

const PNF = libphonenumber.PhoneNumberFormat
export const PhoneNumberFormat = PNF

export const phoneUtil = libphonenumber.PhoneNumberUtil.getInstance()
export const ValidationResult = libphonenumber.PhoneNumberUtil.ValidationResult
const supported = phoneUtil.getSupportedRegions()

export type CountryData = {
  alpha2: string
  callingCode: string
  emoji: string
  emojiText: string
  example: string
  name: string
  pickerText: string
}

let _countryDataLoaded = false
let _countryDataRaw: {[key: string]: CountryData} = {}
let _codeToCountryRaw: {[key: string]: string} = {}
github miparnisari / arg.js / src / phone.js View on Github external
/**
 * @module phone
 */

var phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
var PNF = require('google-libphonenumber').PhoneNumberFormat;

/**
 * @description Cleans a phone number
 * @example returns +5491156623011 for 1556623011
 * @param {string} targetPhone phone number
 * @param {string} areaCode area code, default is 11
 * @returns {string} Cleaned phone number
 */
var clean = function (targetPhone, areaCode) {
  var defaultCountry = 'AR';
  areaCode = areaCode || '11';

  var tel;
  try {
    tel = phoneUtil.parse(targetPhone, defaultCountry);
github Colored-Coins / Colored-Coins-Block-Explorer / app / modules / validator.js View on Github external
var expressValidator = require('express-validator')
var validator = require('validator')
var cs = require('coinstring')
var bs58 = require('bs58')
var ecdsa = require('ecdsa')
var ecurve = require('ecurve')
var libphonenumber = require('google-libphonenumber')
var phoneUtils = libphonenumber.PhoneNumberUtil.getInstance()

var hash_array = [
  {
    name: 'bitcoin',
    value: 0x00
  }, {
    name: 'bitcoin_script_hash',
    value: 0x05
  }, {
    name: 'testnet',
    value: 0x6F
  }, {
    name: 'testnet_script_hash',
    value: 0xC4
  }, {
    name: 'dogecoin',
github keybase / client / shared / util / phone-numbers / index.tsx View on Github external
import {isMobile} from '../../constants/platform'
import libphonenumber from 'google-libphonenumber'

const PNF = libphonenumber.PhoneNumberFormat
export const PhoneNumberFormat = PNF

export const phoneUtil = libphonenumber.PhoneNumberUtil.getInstance()
export const ValidationResult = libphonenumber.PhoneNumberUtil.ValidationResult
const supported = phoneUtil.getSupportedRegions()

export type CountryData = {
  alpha2: string
  callingCode: string
  emoji: string
  emojiText: string
  example: string
  name: string
  pickerText: string
}

let _countryDataLoaded = false
let _countryDataRaw: {[key: string]: CountryData} = {}
let _codeToCountryRaw: {[key: string]: string} = {}
github LLK / scratch-www / src / components / forms / validations.jsx View on Github external
const defaults = require('lodash.defaultsdeep');
const intl = require('../../lib/intl.jsx');
const libphonenumber = require('google-libphonenumber');
const omit = require('lodash.omit');
const phoneNumberUtil = libphonenumber.PhoneNumberUtil.getInstance();
const PropTypes = require('prop-types');
const React = require('react');

module.exports.validations = {
    notEquals: (values, value, neq) => (value !== neq),
    notEqualsField: (values, value, field) => (value !== values[field]),
    isPhone: (values, value) => {
        if (typeof value === 'undefined') return true;
        if (value && value.national_number === '+') return true;
        try {
            const parsed = phoneNumberUtil.parse(value.national_number, value.country_code.iso2);
            return phoneNumberUtil.isValidNumber(parsed);
        } catch (err) {
            return false;
        }
    }