123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import Metadata from './metadata.js'
- import checkNumberLength from './helpers/checkNumberLength.js'
- export default function isPossiblePhoneNumber(input, options, metadata) {
-
- if (options === undefined) {
- options = {}
- }
- metadata = new Metadata(metadata)
- if (options.v2) {
- if (!input.countryCallingCode) {
- throw new Error('Invalid phone number object passed')
- }
- metadata.selectNumberingPlan(input.countryCallingCode)
- } else {
- if (!input.phone) {
- return false
- }
- if (input.country) {
- if (!metadata.hasCountry(input.country)) {
- throw new Error(`Unknown country: ${input.country}`)
- }
- metadata.country(input.country)
- } else {
- if (!input.countryCallingCode) {
- throw new Error('Invalid phone number object passed')
- }
- metadata.selectNumberingPlan(input.countryCallingCode)
- }
- }
-
- if (metadata.possibleLengths()) {
- return isPossibleNumber(input.phone || input.nationalNumber, metadata)
- } else {
-
-
-
-
-
-
- if (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {
-
-
- return true
- } else {
- throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.');
- }
- }
- }
- export function isPossibleNumber(nationalNumber, metadata) {
- switch (checkNumberLength(nationalNumber, metadata)) {
- case 'IS_POSSIBLE':
- return true
-
-
-
-
- default:
- return false
- }
- }
|