react-phone-number-input
Version:
Telephone number input React component
17 lines (14 loc) • 787 B
JavaScript
import { getCountryCallingCode, Metadata } from 'libphonenumber-js/core';
var ONLY_DIGITS_REGEXP = /^\d+$/;
export default function getInternationalPhoneNumberPrefix(country, metadata) {
// Standard international phone number prefix: "+" and "country calling code".
var prefix = '+' + getCountryCallingCode(country, metadata); // Get "leading digits" for a phone number of the country.
// If there're "leading digits" then they can be part of the prefix too.
metadata = new Metadata(metadata);
metadata.country(country);
if (metadata.numberingPlan.leadingDigits() && ONLY_DIGITS_REGEXP.test(metadata.numberingPlan.leadingDigits())) {
prefix += metadata.numberingPlan.leadingDigits();
}
return prefix;
}
//# sourceMappingURL=getInternationalPhoneNumberPrefix.js.map