Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Get Country from the international phone number

/// <summary>
/// Returns the Country based on an international dialing code.
/// </summary>
public static Country? GetCountry(ReadOnlySpan<char> phoneNumber) {
  if (phoneNumber.Length==0) return null;

  var isFirstDigit = true;
  DigitInfo? digitInfo = null;
  Country? country = null;
  foreach (var digitChar in phoneNumber) {
    var digitIndex = digitChar - '0';
    if (isFirstDigit) {
      isFirstDigit = false;
      digitInfo = ByPhone[digitIndex];
    } else {
      if (digitInfo!.Digits is null) return country;

      digitInfo = digitInfo.Digits[digitIndex];
    }
    if (digitInfo is null) return country;

    country = digitInfo.Country??country;
  }
  return country;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript 
Javascript :: react clear input after button click 
Javascript :: java script to send email 
Javascript :: adding all elements in an array javascript 
Javascript :: spring boot map json to object in controller 
Javascript :: localstorage.setitem 
Javascript :: js modulo not working 
Javascript :: date difference without weekends using moment js 
Javascript :: react native elements bottom sheet 
Javascript :: react native fontsize not affected by phone settings 
Javascript :: javascript getHours from epoch 
Javascript :: sequelize findall 2 attributes 
Javascript :: jstree expend all node 
Javascript :: angular blank page no errors 
Javascript :: javascript convert string to bool 
Javascript :: sort method js 
Javascript :: prototype in javascript class 
Javascript :: change element text innerhtml keeping the elements or tags inside 
Javascript :: exponent javascript 
Javascript :: on:click svelte arguments 
Javascript :: promises in es6 
Javascript :: angular get route last segment 
Javascript :: how to set random dice image with js 
Javascript :: not equal to in js 
Javascript :: javascript sleep 1 minute 
Javascript :: how to create a react app 
Javascript :: When JavaScript was invented month?* 
Javascript :: set function to execute at certain time js 
Javascript :: google places autocomplete react native 
Javascript :: javascript url 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =