Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
}
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;
}
}
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();
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();
/**
* 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});
/**
* 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
*/