B2G/gecko/dom/phonenumberutils/PhoneNumber.jsm
// international dial prefixes and country codes.
international dial prefixes and country codes.
international dial prefixes and country codes .
function ParseNumber(number, defaultRegion) {
    var ret;
    number = NormalizeNumber(number);
    if (!defaultRegion && number[0] !== '+')
      return null;
    if (number[0] === '+')
      return ParseInternationalNumber(number.replace(LEADING_PLUS_CHARS_PATTERN, ""));
    var md = FindMetaDataForRegion(defaultRegion.toUpperCase());
    if (md.internationalPrefix.test(number)) {
      var possibleNumber = number.replace(md.internationalPrefix, "");
      if (ret = ParseInternationalNumber(possibleNumber))
        return ret;
    }
    if (md.nationalPrefixForParsing) {
      var withoutPrefix = number.replace(md.nationalPrefixForParsing,
                                         md.nationalPrefixTransformRule || '');
      if (ret = ParseNationalNumber(withoutPrefix, md))
        return ret;
    } else {
      var nationalPrefix = md.nationalPrefix;
      if (nationalPrefix && number.indexOf(nationalPrefix) == 0 &&
          (ret = ParseNationalNumber(number.substr(nationalPrefix.length), md))) {
        return ret;
      }
    }
    if (ret = ParseNationalNumber(number, md))
      return ret;
    if (ret = ParseInternationalNumber(number))
      return ret;
    if (md.possiblePattern.test(number))
      return new NationalNumber(md, number);
    return null;
  }
function ParseNumber ( number , defaultRegion ) { var ret ; number = NormalizeNumber ( number ) ; if ( ! defaultRegion && number [ 0 ] !== '+' ) return null ; if ( number [ 0 ] === '+' ) return ParseInternationalNumber ( number . replace ( LEADING_PLUS_CHARS_PATTERN , "" ) ) ; var md = FindMetaDataForRegion ( defaultRegion . toUpperCase ( ) ) ; if ( md . internationalPrefix . test ( number ) ) { var possibleNumber = number . replace ( md . internationalPrefix , "" ) ; if ( ret = ParseInternationalNumber ( possibleNumber ) ) return ret ; } if ( md . nationalPrefixForParsing ) { var withoutPrefix = number . replace ( md . nationalPrefixForParsing , md . nationalPrefixTransformRule || '' ) ; if ( ret = ParseNationalNumber ( withoutPrefix , md ) ) return ret ; } else { var nationalPrefix = md . nationalPrefix ; if ( nationalPrefix && number . indexOf ( nationalPrefix ) == 0 && ( ret = ParseNationalNumber ( number . substr ( nationalPrefix . length ) , md ) ) ) { return ret ; } } if ( ret = ParseNationalNumber ( number , md ) ) return ret ; if ( ret = ParseInternationalNumber ( number ) ) return ret ; if ( md . possiblePattern . test ( number ) ) return new NationalNumber ( md , number ) ; return null ; }
international dial prefixes and country codes.
international dial prefixes and country codes .
// Remove formating characters and whitespace. // If there is no defaultRegion, we can't parse international access codes. // Detect and strip leading '+'. // Lookup the meta data for the given region. // See if the number starts with an international prefix, and if the // number resulting from stripping the code is valid, then remove the // prefix and flag the number as international. // This is not an international number. See if its a national one for // the current region. National numbers can start with the national // prefix, or without. // Some regions have specific national prefix parse rules. Apply those. // If there is no specific national prefix rule, just strip off the // national prefix from the beginning of the number (if there is one). // Now lets see if maybe its an international number after all, but // without '+' or the international prefix. // If the number matches the possible numbers of the current region, // return it as a possible number. // We couldn't parse the number at all.