Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {
// 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';
}
// 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';
}
function isValidNumber(number, countryCode) {
try {
var phoneUtil = libphonenumber.PhoneNumberUtil.getInstance();
var numberObj = phoneUtil.parseAndKeepRawInput(number, countryCode);
return phoneUtil.isValidNumber(numberObj);
} catch (e) {
return false;
}
}
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} = {}
/**
* @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);
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',
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} = {}
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;
}
}