| @ -0,0 +1,61 @@ | |||||
| Info: | |||||
| ===== | |||||
| Google's JavaScript library for parsing, formatting, and validating | |||||
| international phone numbers. | |||||
| How to setup: | |||||
| ============= | |||||
| 1. Checkout closure-library next to libphonenumber: | |||||
| e.g. | |||||
| svn checkout http://libphonenumber.googlecode.com/svn/trunk/ ~/src/libphonenumber | |||||
| svn checkout http://closure-library.googlecode.com/svn/trunk/ ~/src/closure-library | |||||
| (Or change the path of the <script src=""> in the html pages to point to | |||||
| wherever base.js is located.) | |||||
| 2. Run the unit tests to make sure everything is working. Open the following | |||||
| pages with your web browser: | |||||
| javascript/i18n/phonenumbers/phonenumberutil_test.html | |||||
| javascript/i18n/phonenumbers/asyoutypeformatter_test.html | |||||
| 3. Run the demo: javascript/i18n/phonenumbers/demo.html | |||||
| How to update: | |||||
| ============== | |||||
| The JavaScript library is ported from the Java implementation (revision 39). | |||||
| When the Java project gets updated follow these steps to update the JavaScript | |||||
| project: | |||||
| 1. If the protocol buffers (phonemetadata.proto and phonenumber.proto) | |||||
| have changed: | |||||
| a. Manually update the .pb.js files with the changes of the .proto files. | |||||
| b. Manually update the following JavaScript functions in | |||||
| javascript/i18n/phonenumbers/phonenumberutil.js: | |||||
| i18n.phonenumbers.PhoneNumberDesc.prototype.exactlySameAs(other) | |||||
| i18n.phonenumbers.PhoneNumber.prototype.exactlySameAs(other) | |||||
| c. Manually update the toJsArray() Java methods in | |||||
| /java/resources/com/google/i18n/phonenumbers/BuildMetadataJSON.java | |||||
| 2. If the phone number metadata in the XML format has changed | |||||
| (java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml) | |||||
| run the following commands to regenerate metadata.js and | |||||
| metadatafortesting.js: | |||||
| ant -f java/build.xml | |||||
| java -cp java/build/classes \ | |||||
| com.google.i18n.phonenumbers.BuildMetadataProtoFromXml \ | |||||
| java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml \ | |||||
| javascript/i18n/phonenumbers/metadata.js false json | |||||
| java -cp java/build/classes \ | |||||
| com.google.i18n.phonenumbers.BuildMetadataProtoFromXml \ | |||||
| java/resources/com/google/i18n/phonenumbers/test/PhoneNumberMetaDataForTesting.xml \ | |||||
| javascript/i18n/phonenumbers/metadatafortesting.js false json | |||||
| 3. Manually port any changes of the Java code to the JavaScript code: | |||||
| PhoneNumberUtil.java => phonenumberutil.js | |||||
| AsYouTypeFormatter.java => asyoutypeformatter.js | |||||
| PhoneNumberUtilTest.java => phonenumberutil_test.js | |||||
| AsYouTypeFormatterTest.java => asyoutypeformatter_test.js | |||||
| @ -0,0 +1,657 @@ | |||||
| // Copyright (C) 2010 Google Inc. | |||||
| // | |||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| // you may not use this file except in compliance with the License. | |||||
| // You may obtain a copy of the License at | |||||
| // | |||||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||||
| // | |||||
| // Unless required by applicable law or agreed to in writing, software | |||||
| // distributed under the License is distributed on an "AS-IS" BASIS, | |||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| // See the License for the specific language governing permissions and | |||||
| // limitations under the License. | |||||
| /** | |||||
| * @fileoverview A formatter which formats phone numbers as they are entered. | |||||
| * (based on the java implementation). | |||||
| * | |||||
| * An AsYouTypeFormatter could be created by new AsYouTypeFormatter(). After | |||||
| * that digits could be added by invoking the inputDigit method on the formatter | |||||
| * instance, and the partially formatted phone number will be returned each time | |||||
| * a digit is added. The clear method should be invoked before a new number | |||||
| * needs to be formatted. | |||||
| * | |||||
| * See testAsYouTypeFormatterUS(), testAsYouTestFormatterGB() and | |||||
| * testAsYouTypeFormatterDE() in asyoutypeformatter_test.js for more details | |||||
| * on how the formatter is to be used. | |||||
| * | |||||
| * @author Nikolaos Trogkanis | |||||
| */ | |||||
| goog.provide('i18n.phonenumbers.AsYouTypeFormatter'); | |||||
| goog.require('goog.string.StringBuffer'); | |||||
| goog.require('i18n.phonenumbers.NumberFormat'); | |||||
| goog.require('i18n.phonenumbers.PhoneMetadata'); | |||||
| goog.require('i18n.phonenumbers.PhoneMetadataCollection'); | |||||
| goog.require('i18n.phonenumbers.PhoneNumber'); | |||||
| goog.require('i18n.phonenumbers.PhoneNumber.CountryCodeSource'); | |||||
| goog.require('i18n.phonenumbers.PhoneNumberDesc'); | |||||
| goog.require('i18n.phonenumbers.PhoneNumberUtil'); | |||||
| goog.require('i18n.phonenumbers.metadata'); | |||||
| /** | |||||
| * Constructs a light-weight formatter which does no formatting, but outputs | |||||
| * exactly what is fed into the inputDigit method. | |||||
| * | |||||
| * @param {string} regionCode the country/region where the phone number is being | |||||
| * entered. | |||||
| * @constructor | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter = function(regionCode) { | |||||
| /** | |||||
| * @type {boolean} | |||||
| * @private | |||||
| */ | |||||
| this.ableToFormat_ = true; | |||||
| /** | |||||
| * @type {boolean} | |||||
| * @private | |||||
| */ | |||||
| this.isInternationalFormatting_ = false; | |||||
| /** | |||||
| * @type {i18n.phonenumbers.PhoneNumberUtil} | |||||
| * @private | |||||
| */ | |||||
| this.phoneUtil_ = i18n.phonenumbers.PhoneNumberUtil.getInstance(); | |||||
| // The digits that have not been entered yet will be represented by a \u2008, | |||||
| // the punctuation space. | |||||
| /** | |||||
| * @type {string} | |||||
| * @private | |||||
| */ | |||||
| this.digitPlaceholder_ = '\u2008'; | |||||
| /** | |||||
| * @type {RegExp} | |||||
| * @private | |||||
| */ | |||||
| this.digitPattern_ = new RegExp(this.digitPlaceholder_); | |||||
| /** | |||||
| * @type {number} | |||||
| * @private | |||||
| */ | |||||
| this.lastMatchPosition_ = 0; | |||||
| /** | |||||
| * The position of a digit upon which inputDigitAndRememberPosition is most | |||||
| * recently invoked, as found in the current output. | |||||
| * @type {number} | |||||
| * @private | |||||
| */ | |||||
| this.positionRemembered_ = 0; | |||||
| /** | |||||
| * The position of a digit upon which inputDigitAndRememberPosition is most | |||||
| * recently invoked, as found in the original sequence of characters the user | |||||
| * entered. | |||||
| * @type {number} | |||||
| * @private | |||||
| */ | |||||
| this.originalPosition_ = 0; | |||||
| /** | |||||
| * A pattern that is used to match character classes in regular expressions. | |||||
| * An example of a character class is [1-4]. | |||||
| * @type {RegExp} | |||||
| * @private | |||||
| */ | |||||
| this.CHARACTER_CLASS_PATTERN_ = /\[([^\[\]])*\]/g; | |||||
| /** | |||||
| * Any digit in a regular expression that actually denotes a digit. For | |||||
| * example, in the regular expression 80[0-2]\d{6,10}, the first 2 digits | |||||
| * (8 and 0) are standalone digits, but the rest are not. | |||||
| * Two look-aheads are needed because the number following \\d could be a | |||||
| * two-digit number, since the phone number can be as long as 15 digits. | |||||
| * @type {RegExp} | |||||
| * @private | |||||
| */ | |||||
| this.STANDALONE_DIGIT_PATTERN_ = /\d(?=[^,}][^,}])/g; | |||||
| /** | |||||
| * @type {!goog.string.StringBuffer} | |||||
| * @private | |||||
| */ | |||||
| this.accruedInput_ = new goog.string.StringBuffer(); | |||||
| /** | |||||
| * @type {!goog.string.StringBuffer} | |||||
| * @private | |||||
| */ | |||||
| this.accruedInputWithoutFormatting_ = new goog.string.StringBuffer(); | |||||
| /** | |||||
| * @type {!goog.string.StringBuffer} | |||||
| * @private | |||||
| */ | |||||
| this.currentOutput_ = new goog.string.StringBuffer(); | |||||
| /** | |||||
| * @type {!goog.string.StringBuffer} | |||||
| * @private | |||||
| */ | |||||
| this.prefixBeforeNationalNumber_ = new goog.string.StringBuffer(); | |||||
| /** | |||||
| * @type {!goog.string.StringBuffer} | |||||
| * @private | |||||
| */ | |||||
| this.nationalNumber_ = new goog.string.StringBuffer(); | |||||
| /** | |||||
| * @type {string} | |||||
| * @private | |||||
| */ | |||||
| this.defaultCountry_ = regionCode; | |||||
| this.initializeCountrySpecificInfo_(this.defaultCountry_); | |||||
| /** | |||||
| * @type {i18n.phonenumbers.PhoneMetadata} | |||||
| * @private | |||||
| */ | |||||
| this.defaultMetaData_ = this.currentMetaData_; | |||||
| }; | |||||
| /** | |||||
| * @param {string} regionCode | |||||
| * @private | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype.initializeCountrySpecificInfo_ = | |||||
| function(regionCode) { | |||||
| /** @type {i18n.phonenumbers.PhoneMetadata} */ | |||||
| this.currentMetaData_ = this.phoneUtil_.getMetadataForRegion(regionCode); | |||||
| /** @type {RegExp} */ | |||||
| this.nationalPrefixForParsing_ = new RegExp('^(' + this.currentMetaData_ | |||||
| .getNationalPrefixForParsing() + ')'); | |||||
| /** @type {RegExp} */ | |||||
| this.internationalPrefix_ = new RegExp('^(' + '\\+|' + | |||||
| this.currentMetaData_.getInternationalPrefix() + ')'); | |||||
| }; | |||||
| /** | |||||
| * @param {string} leadingFourDigitsOfNationalNumber | |||||
| * @private | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype.chooseFormatAndCreateTemplate_ = | |||||
| function(leadingFourDigitsOfNationalNumber) { | |||||
| /** @type {Array.<i18n.phonenumbers.NumberFormat>} */ | |||||
| var formatList = this.getAvailableFormats_(leadingFourDigitsOfNationalNumber); | |||||
| if (formatList.length < 1) { | |||||
| this.ableToFormat_ = false; | |||||
| } else { | |||||
| // When there are multiple available formats, the formatter uses the first | |||||
| // format. | |||||
| /** @type {i18n.phonenumbers.NumberFormat} */ | |||||
| var format = formatList[0]; | |||||
| if (!this.createFormattingTemplate_(format)) { | |||||
| this.ableToFormat_ = false; | |||||
| } else { | |||||
| this.currentOutput_ = | |||||
| new goog.string.StringBuffer(this.formattingTemplate_); | |||||
| } | |||||
| } | |||||
| }; | |||||
| /** | |||||
| * @param {string} leadingFourDigits | |||||
| * @return {Array.<i18n.phonenumbers.NumberFormat>} | |||||
| * @private | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype.getAvailableFormats_ = | |||||
| function(leadingFourDigits) { | |||||
| /** @type {Array.<i18n.phonenumbers.NumberFormat>} */ | |||||
| var matchedList = []; | |||||
| /** @type {Array.<i18n.phonenumbers.NumberFormat>} */ | |||||
| var formatList = (this.isInternationalFormatting_ && this.currentMetaData_ | |||||
| .intlNumberFormatCount() > 0) ? this.currentMetaData_ | |||||
| .intlNumberFormatArray() : this.currentMetaData_.numberFormatArray(); | |||||
| /** @type {number} */ | |||||
| var formatListLength = formatList.length; | |||||
| for (var i = 0; i < formatListLength; ++i) { | |||||
| /** @type {i18n.phonenumbers.NumberFormat} */ | |||||
| var format = formatList[i]; | |||||
| if (format.hasLeadingDigits()) { | |||||
| /** @type {RegExp} */ | |||||
| var leadingDigitsPattern = | |||||
| new RegExp('^(' + format.getLeadingDigits() + ')'); | |||||
| if (leadingDigitsPattern.test(leadingFourDigits)) { | |||||
| matchedList.push(format); | |||||
| } | |||||
| } else { | |||||
| matchedList.push(format); | |||||
| } | |||||
| } | |||||
| return matchedList; | |||||
| }; | |||||
| /** | |||||
| * @param {i18n.phonenumbers.NumberFormat} format | |||||
| * @return {boolean} | |||||
| * @private | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype.createFormattingTemplate_ = | |||||
| function(format) { | |||||
| /** @type {string} */ | |||||
| var numberFormat = format.getFormatOrDefault(); | |||||
| /** @type {string} */ | |||||
| var numberPattern = format.getPatternOrDefault(); | |||||
| // The formatter doesn't format numbers when numberPattern contains '|', e.g. | |||||
| // (20|3)\d{4}. In those cases we quickly return. | |||||
| if (numberPattern.indexOf('|') != -1) { | |||||
| return false; | |||||
| } | |||||
| // Replace anything in the form of [..] with \d | |||||
| numberPattern = numberPattern.replace(this.CHARACTER_CLASS_PATTERN_, '\\d'); | |||||
| // Replace any standalone digit (not the one in d{}) with \d | |||||
| numberPattern = numberPattern.replace(this.STANDALONE_DIGIT_PATTERN_, '\\d'); | |||||
| this.formattingTemplate_ = this.getFormattingTemplate_(numberPattern, | |||||
| numberFormat); | |||||
| return true; | |||||
| }; | |||||
| /** | |||||
| * Gets a formatting template which could be used to efficiently format a | |||||
| * partial number where digits are added one by one. | |||||
| * | |||||
| * @param {string} numberPattern | |||||
| * @param {string} numberFormat | |||||
| * @return {string} | |||||
| * @private | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype.getFormattingTemplate_ = | |||||
| function(numberPattern, numberFormat) { | |||||
| // Creates a phone number consisting only of the digit 9 that matches the | |||||
| // numberPattern by applying the pattern to the longestPhoneNumber string. | |||||
| /** @type {string} */ | |||||
| var longestPhoneNumber = '999999999999999'; | |||||
| /** @type {Array.<string>} */ | |||||
| var m = longestPhoneNumber.match(numberPattern); | |||||
| // this match will always succeed | |||||
| /** @type {string} */ | |||||
| var aPhoneNumber = m[0]; | |||||
| // Formats the number according to numberFormat | |||||
| /** @type {string} */ | |||||
| var template = aPhoneNumber.replace(new RegExp(numberPattern, 'g'), | |||||
| numberFormat); | |||||
| // Replaces each digit with character digitPlaceholder | |||||
| template = template.replace(new RegExp('9', 'g'), this.digitPlaceholder_); | |||||
| return template; | |||||
| }; | |||||
| /** | |||||
| * Clears the internal state of the formatter, so it could be reused. | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype.clear = function() { | |||||
| this.accruedInput_.clear(); | |||||
| this.accruedInputWithoutFormatting_.clear(); | |||||
| this.currentOutput_.clear(); | |||||
| this.lastMatchPosition_ = 0; | |||||
| this.prefixBeforeNationalNumber_.clear(); | |||||
| this.nationalNumber_.clear(); | |||||
| this.ableToFormat_ = true; | |||||
| this.positionRemembered_ = 0; | |||||
| this.originalPosition_ = 0; | |||||
| this.isInternationalFormatting_ = false; | |||||
| if (this.currentMetaData_ != this.defaultMetaData_) { | |||||
| this.initializeCountrySpecificInfo_(this.defaultCountry_); | |||||
| } | |||||
| }; | |||||
| /** | |||||
| * Formats a phone number on-the-fly as each digit is entered. | |||||
| * | |||||
| * @param {string} nextChar the most recently entered digit of a phone number. | |||||
| * Formatting characters are allowed, but they are removed from the result. | |||||
| * @return {string} the partially formatted phone number. | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype.inputDigit = function(nextChar) { | |||||
| return this.inputDigitWithOptionToRememberPosition_(nextChar, false); | |||||
| }; | |||||
| /** | |||||
| * Same as inputDigit, but remembers the position where nextChar is inserted, so | |||||
| * that it could be retrieved later by using getRememberedPosition(). The | |||||
| * remembered position will be automatically adjusted if additional formatting | |||||
| * characters are later inserted/removed in front of nextChar. | |||||
| * | |||||
| * @param {string} nextChar | |||||
| * @return {string} | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype.inputDigitAndRememberPosition = | |||||
| function(nextChar) { | |||||
| return this.inputDigitWithOptionToRememberPosition_(nextChar, true); | |||||
| }; | |||||
| /** | |||||
| * @param {string} nextChar | |||||
| * @param {boolean} rememberPosition | |||||
| * @return {string} | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype. | |||||
| inputDigitWithOptionToRememberPosition_ = function(nextChar, | |||||
| rememberPosition) { | |||||
| this.accruedInput_.append(nextChar); | |||||
| if (rememberPosition) { | |||||
| this.positionRemembered_ = this.accruedInput_.getLength(); | |||||
| this.originalPosition_ = this.positionRemembered_; | |||||
| } | |||||
| // We do formatting on-the-fly only when each character entered is either a | |||||
| // plus sign or a digit. | |||||
| if (!i18n.phonenumbers.PhoneNumberUtil.VALID_START_CHAR_PATTERN | |||||
| .test(nextChar)) { | |||||
| this.ableToFormat_ = false; | |||||
| } | |||||
| if (!this.ableToFormat_) { | |||||
| this.resetPositionOnFailureToFormat_(); | |||||
| return this.accruedInput_.toString(); | |||||
| } | |||||
| nextChar = this.normalizeAndAccrueDigitsAndPlusSign_(nextChar); | |||||
| // We start to attempt to format only when at least 6 digits (the plus sign is | |||||
| // counted as a digit as well for this purpose) have been entered. | |||||
| switch (this.accruedInputWithoutFormatting_.getLength()) { | |||||
| case 0: // this is the case where the first few inputs are neither digits nor | |||||
| // the plus sign. | |||||
| case 1: | |||||
| case 2: | |||||
| case 3: | |||||
| case 4: | |||||
| case 5: | |||||
| return this.accruedInput_.toString(); | |||||
| case 6: | |||||
| if (!this.extractIddAndValidCountryCode_()) { | |||||
| this.ableToFormat_ = false; | |||||
| return this.accruedInput_.toString(); | |||||
| } | |||||
| this.removeNationalPrefixFromNationalNumber_(); | |||||
| return this.attemptToChooseFormattingPattern_(rememberPosition); | |||||
| default: | |||||
| if (this.nationalNumber_.getLength() > 4) { | |||||
| // The formatting pattern is already chosen. | |||||
| /** @type {string} */ | |||||
| var temp = this.inputDigitHelper_(nextChar, rememberPosition); | |||||
| return this.ableToFormat_ ? | |||||
| this.prefixBeforeNationalNumber_.toString() + temp : temp; | |||||
| } else { | |||||
| return this.attemptToChooseFormattingPattern_(rememberPosition); | |||||
| } | |||||
| } | |||||
| }; | |||||
| /** | |||||
| * @private | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype.resetPositionOnFailureToFormat_ = | |||||
| function() { | |||||
| if (this.positionRemembered_ > 0) { | |||||
| this.positionRemembered_ = this.originalPosition_; | |||||
| this.currentOutput_.clear(); | |||||
| } | |||||
| }; | |||||
| /** | |||||
| * Returns the current position in the partially formatted phone number of the | |||||
| * character which was previously passed in as the parameter of | |||||
| * inputDigitAndRememberPosition(). | |||||
| * | |||||
| * @return {number} | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype.getRememberedPosition = | |||||
| function() { | |||||
| return this.positionRemembered_; | |||||
| }; | |||||
| /** | |||||
| * Attempts to set the formatting template and returns a string which contains | |||||
| * the formatted version of the digits entered so far. | |||||
| * | |||||
| * @param {boolean} rememberPosition | |||||
| * @return {string} | |||||
| * @private | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype. | |||||
| attemptToChooseFormattingPattern_ = function(rememberPosition) { | |||||
| /** @type {string} */ | |||||
| var nationalNumber = this.nationalNumber_.toString(); | |||||
| /** @type {number} */ | |||||
| var nationalNumberLength = nationalNumber.length; | |||||
| // We start to attempt to format only when as least 4 digits of national | |||||
| // number (excluding national prefix) have been entered. | |||||
| if (nationalNumberLength >= 4) { | |||||
| this.chooseFormatAndCreateTemplate_(nationalNumber.substring(0, 4)); | |||||
| return this.inputAccruedNationalNumber_(rememberPosition); | |||||
| } else { | |||||
| if (rememberPosition) { | |||||
| this.positionRemembered_ = | |||||
| this.prefixBeforeNationalNumber_.length() + nationalNumberLength; | |||||
| } | |||||
| return this.prefixBeforeNationalNumber_.toString() + | |||||
| this.nationalNumber_.toString(); | |||||
| } | |||||
| }; | |||||
| /** | |||||
| * Invokes inputDigitHelper on each digit of the national number accrued, and | |||||
| * returns a formatted string in the end. | |||||
| * | |||||
| * @param {boolean} rememberPosition | |||||
| * @return {string} | |||||
| * @private | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype.inputAccruedNationalNumber_ = | |||||
| function(rememberPosition) { | |||||
| /** @type {number} */ | |||||
| var lengthOfNationalNumber = this.nationalNumber_.getLength(); | |||||
| if (lengthOfNationalNumber > 0) { | |||||
| // The positionRemembered should be only adjusted once in the loop that | |||||
| // follows. | |||||
| /** @type {boolean} */ | |||||
| var positionAlreadyAdjusted = false; | |||||
| /** @type {string} */ | |||||
| var tempNationalNumber = ''; | |||||
| for (var i = 0; i < lengthOfNationalNumber; i++) { | |||||
| tempNationalNumber = | |||||
| this.inputDigitHelper_(this.nationalNumber_.toString().charAt(i), | |||||
| rememberPosition); | |||||
| if (!positionAlreadyAdjusted && | |||||
| this.positionRemembered_ - | |||||
| this.prefixBeforeNationalNumber_.getLength() == i + 1) { | |||||
| this.positionRemembered_ = | |||||
| this.prefixBeforeNationalNumber_.getLength() + | |||||
| tempNationalNumber.length; | |||||
| positionAlreadyAdjusted = true; | |||||
| } | |||||
| } | |||||
| return this.ableToFormat_ ? | |||||
| this.prefixBeforeNationalNumber_.toString() + tempNationalNumber : | |||||
| tempNationalNumber; | |||||
| } else { | |||||
| if (rememberPosition) { | |||||
| this.positionRemembered_ = this.prefixBeforeNationalNumber_.length(); | |||||
| } | |||||
| return this.prefixBeforeNationalNumber_.toString(); | |||||
| } | |||||
| }; | |||||
| /** | |||||
| * @private | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype. | |||||
| removeNationalPrefixFromNationalNumber_ = function() { | |||||
| /** @type {string} */ | |||||
| var nationalNumber = this.nationalNumber_.toString(); | |||||
| /** @type {number} */ | |||||
| var startOfNationalNumber = 0; | |||||
| if (this.currentMetaData_.getCountryCode() == 1 && | |||||
| nationalNumber.charAt(0) == '1') { | |||||
| startOfNationalNumber = 1; | |||||
| this.prefixBeforeNationalNumber_.append('1 '); | |||||
| // Since a space is inserted after the national prefix in this case, we | |||||
| // increase the remembered position by 1 for anything that is after the | |||||
| // national prefix. | |||||
| if (this.positionRemembered_ > | |||||
| this.prefixBeforeNationalNumber_.getLength() - 1) { | |||||
| this.positionRemembered_++; | |||||
| } | |||||
| } else if (this.currentMetaData_.hasNationalPrefix()) { | |||||
| /** @type {Array.<string>} */ | |||||
| var m = nationalNumber.match(this.nationalPrefixForParsing_); | |||||
| if (m != null && m[0] != null && m[0].length > 0) { | |||||
| startOfNationalNumber = m[0].length; | |||||
| this.prefixBeforeNationalNumber_.append(nationalNumber.substring(0, | |||||
| startOfNationalNumber)); | |||||
| } | |||||
| } | |||||
| this.nationalNumber_.clear(); | |||||
| this.nationalNumber_.append(nationalNumber.substring(startOfNationalNumber)); | |||||
| }; | |||||
| /** | |||||
| * Extracts IDD, plus sign and country code to prefixBeforeNationalNumber when | |||||
| * they are available, and places the remaining input into nationalNumber. | |||||
| * | |||||
| * @return {boolean} false when accruedInputWithoutFormatting begins with the | |||||
| * plus sign or valid IDD for defaultCountry, but the sequence of digits | |||||
| * after that does not form a valid country code. It returns true for all | |||||
| * other cases. | |||||
| * @private | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype.extractIddAndValidCountryCode_ = | |||||
| function() { | |||||
| /** @type {string} */ | |||||
| var accruedInputWithoutFormatting = | |||||
| this.accruedInputWithoutFormatting_.toString(); | |||||
| this.nationalNumber_.clear(); | |||||
| /** @type {Array.<string>} */ | |||||
| var m = accruedInputWithoutFormatting.match(this.internationalPrefix_); | |||||
| if (m != null && m[0] != null && m[0].length > 0) { | |||||
| this.isInternationalFormatting_ = true; | |||||
| /** @type {number} */ | |||||
| var startOfCountryCode = m[0].length; | |||||
| /** @type {!goog.string.StringBuffer} */ | |||||
| var numberIncludeCountryCode = new goog.string.StringBuffer( | |||||
| accruedInputWithoutFormatting.substring(startOfCountryCode)); | |||||
| /** @type {number} */ | |||||
| var countryCode = this.phoneUtil_.extractCountryCode( | |||||
| numberIncludeCountryCode, this.nationalNumber_); | |||||
| if (countryCode == 0) { | |||||
| return false; | |||||
| } else { | |||||
| /** @type {string} */ | |||||
| var newRegionCode = | |||||
| this.phoneUtil_.getRegionCodeForCountryCode(countryCode); | |||||
| if (newRegionCode != this.defaultCountry_) { | |||||
| this.initializeCountrySpecificInfo_(newRegionCode); | |||||
| } | |||||
| this.prefixBeforeNationalNumber_.append(accruedInputWithoutFormatting | |||||
| .substring(0, startOfCountryCode)); | |||||
| if (accruedInputWithoutFormatting.charAt(0) != | |||||
| i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN) { | |||||
| if (this.positionRemembered_ > | |||||
| this.prefixBeforeNationalNumber_.getLength()) { | |||||
| // Since a space will be inserted in front of the country code in this | |||||
| // case, we increase the remembered position by 1. | |||||
| this.positionRemembered_++; | |||||
| } | |||||
| this.prefixBeforeNationalNumber_.append(' '); | |||||
| } | |||||
| /** @type {string} */ | |||||
| var countryCodeString = '' + countryCode; | |||||
| if (this.positionRemembered_ > | |||||
| this.prefixBeforeNationalNumber_.getLength() + | |||||
| countryCodeString.length) { | |||||
| // Since a space will be inserted after the country code in this case, | |||||
| // we increase the remembered position by 1. | |||||
| this.positionRemembered_++; | |||||
| } | |||||
| this.prefixBeforeNationalNumber_.append(countryCodeString).append(' '); | |||||
| } | |||||
| } else { | |||||
| this.nationalNumber_.clear(); | |||||
| this.nationalNumber_.append(accruedInputWithoutFormatting); | |||||
| } | |||||
| return true; | |||||
| }; | |||||
| /** | |||||
| * Accrues digits and the plus sign to accruedInputWithoutFormatting for later | |||||
| * use. If nextChar contains a digit in non-ASCII format (e.g. the full-width | |||||
| * version of digits), it is first normalized to the ASCII version. The return | |||||
| * value is nextChar itself, or its normalized version, if nextChar is a digit | |||||
| * in non-ASCII format. | |||||
| * | |||||
| * @param {string} nextChar | |||||
| * @return {string} | |||||
| * @private | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype. | |||||
| normalizeAndAccrueDigitsAndPlusSign_ = function(nextChar) { | |||||
| if (nextChar == i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN) { | |||||
| this.accruedInputWithoutFormatting_.append(nextChar); | |||||
| } | |||||
| if (nextChar in i18n.phonenumbers.PhoneNumberUtil.DIGIT_MAPPINGS) { | |||||
| nextChar = i18n.phonenumbers.PhoneNumberUtil.DIGIT_MAPPINGS[nextChar]; | |||||
| this.accruedInputWithoutFormatting_.append(nextChar); | |||||
| this.nationalNumber_.append(nextChar); | |||||
| } | |||||
| return nextChar; | |||||
| }; | |||||
| /** | |||||
| * @param {string} nextChar | |||||
| * @param {boolean} rememberPosition | |||||
| * @return {string} | |||||
| * @private | |||||
| */ | |||||
| i18n.phonenumbers.AsYouTypeFormatter.prototype.inputDigitHelper_ = | |||||
| function(nextChar, rememberPosition) { | |||||
| if (!(nextChar in i18n.phonenumbers.PhoneNumberUtil.DIGIT_MAPPINGS)) { | |||||
| return this.currentOutput_.toString(); | |||||
| } | |||||
| /** @type {string} */ | |||||
| var currentOutput = this.currentOutput_.toString(); | |||||
| /** @type {string} */ | |||||
| var currentOutput2 = currentOutput.substring(this.lastMatchPosition_); | |||||
| /** @type {number} */ | |||||
| var digitPatternStart = currentOutput2.search(this.digitPattern_); | |||||
| if (digitPatternStart >= 0) { | |||||
| this.currentOutput_ = new goog.string.StringBuffer( | |||||
| currentOutput.substring(0, this.lastMatchPosition_) + | |||||
| currentOutput2.replace(this.digitPattern_, nextChar)); | |||||
| this.lastMatchPosition_ += digitPatternStart; | |||||
| if (rememberPosition) { | |||||
| this.positionRemembered_ = this.prefixBeforeNationalNumber_.getLength() + | |||||
| this.lastMatchPosition_ + 1; | |||||
| } | |||||
| return this.currentOutput_.toString() | |||||
| .substring(0, this.lastMatchPosition_ + 1); | |||||
| } else { | |||||
| // More digits are entered than we could handle. | |||||
| this.currentOutput_.append(nextChar); | |||||
| this.ableToFormat_ = false; | |||||
| this.resetPositionOnFailureToFormat_(); | |||||
| return this.accruedInput_.toString(); | |||||
| } | |||||
| }; | |||||
| @ -0,0 +1,36 @@ | |||||
| <!DOCTYPE html> | |||||
| <html> | |||||
| <!-- | |||||
| Copyright (C) 2010 Google Inc. | |||||
| Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| you may not use this file except in compliance with the License. | |||||
| You may obtain a copy of the License at | |||||
| http://www.apache.org/licenses/LICENSE-2.0 | |||||
| Unless required by applicable law or agreed to in writing, software | |||||
| distributed under the License is distributed on an "AS-IS" BASIS, | |||||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| See the License for the specific language governing permissions and | |||||
| limitations under the License. | |||||
| --> | |||||
| <!-- | |||||
| Author: Nikolaos Trogkanis | |||||
| --> | |||||
| <head> | |||||
| <title>libphonenumber Unit Tests - i18n.phonenumbers - asyoutypeformatter.js</title> | |||||
| <script src="../../../../closure-library/closure/goog/base.js"></script> | |||||
| <script> | |||||
| goog.require('goog.proto2.Message'); | |||||
| </script> | |||||
| <script src="phonemetadata.pb.js"></script> | |||||
| <script src="phonenumber.pb.js"></script> | |||||
| <script src="metadatafortesting.js"></script> | |||||
| <script src="phonenumberutil.js"></script> | |||||
| <script src="asyoutypeformatter.js"></script> | |||||
| <script src="asyoutypeformatter_test.js"></script> | |||||
| </head> | |||||
| <body> | |||||
| </body> | |||||
| </html> | |||||
| @ -0,0 +1,482 @@ | |||||
| // Copyright (C) 2010 Google Inc. | |||||
| // | |||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| // you may not use this file except in compliance with the License. | |||||
| // You may obtain a copy of the License at | |||||
| // | |||||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||||
| // | |||||
| // Unless required by applicable law or agreed to in writing, software | |||||
| // distributed under the License is distributed on an "AS-IS" BASIS, | |||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| // See the License for the specific language governing permissions and | |||||
| // limitations under the License. | |||||
| /** | |||||
| * @fileoverview Unit tests for the AsYouTypeFormatter. | |||||
| * | |||||
| * @author Nikolaos Trogkanis | |||||
| */ | |||||
| goog.require('goog.testing.jsunit'); | |||||
| goog.require('i18n.phonenumbers.AsYouTypeFormatter'); | |||||
| function testAsYouTypeFormatterUS() { | |||||
| /** @type {i18n.phonenumbers.AsYouTypeFormatter} */ | |||||
| var f = new i18n.phonenumbers.AsYouTypeFormatter('US'); | |||||
| assertEquals('6', f.inputDigit('6')); | |||||
| assertEquals('65', f.inputDigit('5')); | |||||
| assertEquals('650', f.inputDigit('0')); | |||||
| assertEquals('6502', f.inputDigit('2')); | |||||
| assertEquals('65025', f.inputDigit('5')); | |||||
| assertEquals('650 253', f.inputDigit('3')); | |||||
| assertEquals('650 253 2', f.inputDigit('2')); | |||||
| assertEquals('650 253 22', f.inputDigit('2')); | |||||
| assertEquals('650 253 222', f.inputDigit('2')); | |||||
| assertEquals('650 253 2222', f.inputDigit('2')); | |||||
| f.clear(); | |||||
| assertEquals('1', f.inputDigit('1')); | |||||
| assertEquals('16', f.inputDigit('6')); | |||||
| assertEquals('165', f.inputDigit('5')); | |||||
| assertEquals('1650', f.inputDigit('0')); | |||||
| assertEquals('16502', f.inputDigit('2')); | |||||
| assertEquals('1 650 25', f.inputDigit('5')); | |||||
| assertEquals('1 650 253', f.inputDigit('3')); | |||||
| assertEquals('1 650 253 2', f.inputDigit('2')); | |||||
| assertEquals('1 650 253 22', f.inputDigit('2')); | |||||
| assertEquals('1 650 253 222', f.inputDigit('2')); | |||||
| assertEquals('1 650 253 2222', f.inputDigit('2')); | |||||
| f.clear(); | |||||
| assertEquals('0', f.inputDigit('0')); | |||||
| assertEquals('01', f.inputDigit('1')); | |||||
| assertEquals('011', f.inputDigit('1')); | |||||
| assertEquals('0114', f.inputDigit('4')); | |||||
| assertEquals('01144', f.inputDigit('4')); | |||||
| assertEquals('011 44 6', f.inputDigit('6')); | |||||
| assertEquals('011 44 61', f.inputDigit('1')); | |||||
| assertEquals('011 44 612', f.inputDigit('2')); | |||||
| assertEquals('011 44 6 123', f.inputDigit('3')); | |||||
| assertEquals('011 44 6 123 1', f.inputDigit('1')); | |||||
| assertEquals('011 44 6 123 12', f.inputDigit('2')); | |||||
| assertEquals('011 44 6 123 123', f.inputDigit('3')); | |||||
| assertEquals('011 44 6 123 123 1', f.inputDigit('1')); | |||||
| assertEquals('011 44 6 123 123 12', f.inputDigit('2')); | |||||
| assertEquals('011 44 6 123 123 123', f.inputDigit('3')); | |||||
| f.clear(); | |||||
| assertEquals('0', f.inputDigit('0')); | |||||
| assertEquals('01', f.inputDigit('1')); | |||||
| assertEquals('011', f.inputDigit('1')); | |||||
| assertEquals('0115', f.inputDigit('5')); | |||||
| assertEquals('01154', f.inputDigit('4')); | |||||
| assertEquals('011 54 9', f.inputDigit('9')); | |||||
| assertEquals('011 54 91', f.inputDigit('1')); | |||||
| assertEquals('011 54 911', f.inputDigit('1')); | |||||
| assertEquals('011 54 9 11 2', f.inputDigit('2')); | |||||
| assertEquals('011 54 9 11 23', f.inputDigit('3')); | |||||
| assertEquals('011 54 9 11 231', f.inputDigit('1')); | |||||
| assertEquals('011 54 9 11 2312', f.inputDigit('2')); | |||||
| assertEquals('011 54 9 11 2312 1', f.inputDigit('1')); | |||||
| assertEquals('011 54 9 11 2312 12', f.inputDigit('2')); | |||||
| assertEquals('011 54 9 11 2312 123', f.inputDigit('3')); | |||||
| assertEquals('011 54 9 11 2312 1234', f.inputDigit('4')); | |||||
| f.clear(); | |||||
| assertEquals('+', f.inputDigit('+')); | |||||
| assertEquals('+4', f.inputDigit('4')); | |||||
| assertEquals('+48', f.inputDigit('8')); | |||||
| assertEquals('+488', f.inputDigit('8')); | |||||
| assertEquals('+4888', f.inputDigit('8')); | |||||
| assertEquals('+48 881', f.inputDigit('1')); | |||||
| assertEquals('+48 88 12', f.inputDigit('2')); | |||||
| assertEquals('+48 88 123', f.inputDigit('3')); | |||||
| assertEquals('+48 88 123 1', f.inputDigit('1')); | |||||
| assertEquals('+48 88 123 12', f.inputDigit('2')); | |||||
| assertEquals('+48 88 123 12 1', f.inputDigit('1')); | |||||
| assertEquals('+48 88 123 12 12', f.inputDigit('2')); | |||||
| } | |||||
| function testAsYouTypeFormatterUSFullWidthCharacters() { | |||||
| /** @type {i18n.phonenumbers.AsYouTypeFormatter} */ | |||||
| var f = new i18n.phonenumbers.AsYouTypeFormatter('US'); | |||||
| assertEquals('\uFF16', f.inputDigit('\uFF16')); | |||||
| assertEquals('\uFF16\uFF15', f.inputDigit('\uFF15')); | |||||
| assertEquals('\uFF16\uFF15\uFF10', f.inputDigit('\uFF10')); | |||||
| assertEquals('\uFF16\uFF15\uFF10\uFF12', f.inputDigit('\uFF12')); | |||||
| assertEquals('\uFF16\uFF15\uFF10\uFF12\uFF15', f.inputDigit('\uFF15')); | |||||
| assertEquals('650 253', f.inputDigit('\uFF13')); | |||||
| assertEquals('650 253 2', f.inputDigit('\uFF12')); | |||||
| assertEquals('650 253 22', f.inputDigit('\uFF12')); | |||||
| assertEquals('650 253 222', f.inputDigit('\uFF12')); | |||||
| assertEquals('650 253 2222', f.inputDigit('\uFF12')); | |||||
| } | |||||
| function testAsYouTypeFormatterUSMobileShortCode() { | |||||
| /** @type {i18n.phonenumbers.AsYouTypeFormatter} */ | |||||
| var f = new i18n.phonenumbers.AsYouTypeFormatter('US'); | |||||
| assertEquals('*', f.inputDigit('*')); | |||||
| assertEquals('*1', f.inputDigit('1')); | |||||
| assertEquals('*12', f.inputDigit('2')); | |||||
| assertEquals('*121', f.inputDigit('1')); | |||||
| assertEquals('*121#', f.inputDigit('#')); | |||||
| } | |||||
| function testAsYouTypeFormatterUSVanityNumber() { | |||||
| /** @type {i18n.phonenumbers.AsYouTypeFormatter} */ | |||||
| var f = new i18n.phonenumbers.AsYouTypeFormatter('US'); | |||||
| assertEquals('8', f.inputDigit('8')); | |||||
| assertEquals('80', f.inputDigit('0')); | |||||
| assertEquals('800', f.inputDigit('0')); | |||||
| assertEquals('800 ', f.inputDigit(' ')); | |||||
| assertEquals('800 M', f.inputDigit('M')); | |||||
| assertEquals('800 MY', f.inputDigit('Y')); | |||||
| assertEquals('800 MY ', f.inputDigit(' ')); | |||||
| assertEquals('800 MY A', f.inputDigit('A')); | |||||
| assertEquals('800 MY AP', f.inputDigit('P')); | |||||
| assertEquals('800 MY APP', f.inputDigit('P')); | |||||
| assertEquals('800 MY APPL', f.inputDigit('L')); | |||||
| assertEquals('800 MY APPLE', f.inputDigit('E')); | |||||
| } | |||||
| function testAsYouTypeFormatterAndRememberPositionUS() { | |||||
| /** @type {i18n.phonenumbers.AsYouTypeFormatter} */ | |||||
| var f = new i18n.phonenumbers.AsYouTypeFormatter('US'); | |||||
| assertEquals('1', f.inputDigitAndRememberPosition('1')); | |||||
| assertEquals(1, f.getRememberedPosition()); | |||||
| assertEquals('16', f.inputDigit('6')); | |||||
| assertEquals('165', f.inputDigit('5')); | |||||
| assertEquals(1, f.getRememberedPosition()); | |||||
| assertEquals('1650', f.inputDigitAndRememberPosition('0')); | |||||
| assertEquals(4, f.getRememberedPosition()); | |||||
| assertEquals('16502', f.inputDigit('2')); | |||||
| assertEquals('1 650 25', f.inputDigit('5')); | |||||
| // Note the remembered position for digit '0' changes from 4 to 5, because a | |||||
| // space is now inserted in the front. | |||||
| assertEquals(5, f.getRememberedPosition()); | |||||
| assertEquals('1 650 253', f.inputDigit('3')); | |||||
| assertEquals('1 650 253 2', f.inputDigit('2')); | |||||
| assertEquals('1 650 253 22', f.inputDigit('2')); | |||||
| assertEquals(5, f.getRememberedPosition()); | |||||
| assertEquals('1 650 253 222', f.inputDigitAndRememberPosition('2')); | |||||
| assertEquals(13, f.getRememberedPosition()); | |||||
| assertEquals('1 650 253 2222', f.inputDigit('2')); | |||||
| assertEquals(13, f.getRememberedPosition()); | |||||
| assertEquals('165025322222', f.inputDigit('2')); | |||||
| assertEquals(10, f.getRememberedPosition()); | |||||
| assertEquals('1650253222222', f.inputDigit('2')); | |||||
| assertEquals(10, f.getRememberedPosition()); | |||||
| f.clear(); | |||||
| assertEquals('1', f.inputDigit('1')); | |||||
| assertEquals('16', f.inputDigit('6')); | |||||
| assertEquals('165', f.inputDigitAndRememberPosition('5')); | |||||
| assertEquals('1650', f.inputDigit('0')); | |||||
| assertEquals(3, f.getRememberedPosition()); | |||||
| assertEquals('16502', f.inputDigit('2')); | |||||
| assertEquals('1 650 25', f.inputDigit('5')); | |||||
| assertEquals(4, f.getRememberedPosition()); | |||||
| assertEquals('1 650 253', f.inputDigit('3')); | |||||
| assertEquals('1 650 253 2', f.inputDigit('2')); | |||||
| assertEquals('1 650 253 22', f.inputDigit('2')); | |||||
| assertEquals(4, f.getRememberedPosition()); | |||||
| assertEquals('1 650 253 222', f.inputDigit('2')); | |||||
| assertEquals('1 650 253 2222', f.inputDigit('2')); | |||||
| assertEquals('165025322222', f.inputDigit('2')); | |||||
| assertEquals(3, f.getRememberedPosition()); | |||||
| assertEquals('1650253222222', f.inputDigit('2')); | |||||
| assertEquals(3, f.getRememberedPosition()); | |||||
| f.clear(); | |||||
| assertEquals('6', f.inputDigit('6')); | |||||
| assertEquals('65', f.inputDigit('5')); | |||||
| assertEquals('650', f.inputDigit('0')); | |||||
| assertEquals('6502', f.inputDigit('2')); | |||||
| assertEquals('65025', f.inputDigitAndRememberPosition('5')); | |||||
| assertEquals(5, f.getRememberedPosition()); | |||||
| assertEquals('650 253', f.inputDigit('3')); | |||||
| assertEquals(6, f.getRememberedPosition()); | |||||
| assertEquals('650 253 2', f.inputDigit('2')); | |||||
| assertEquals('650 253 22', f.inputDigit('2')); | |||||
| assertEquals('650 253 222', f.inputDigit('2')); | |||||
| // No more formatting when semicolon is entered. | |||||
| assertEquals('650253222;', f.inputDigit(';')); | |||||
| assertEquals(5, f.getRememberedPosition()); | |||||
| assertEquals('650253222;2', f.inputDigit('2')); | |||||
| f.clear(); | |||||
| assertEquals('6', f.inputDigit('6')); | |||||
| assertEquals('65', f.inputDigit('5')); | |||||
| assertEquals('650', f.inputDigit('0')); | |||||
| // No more formatting when users choose to do their own formatting. | |||||
| assertEquals('650-', f.inputDigit('-')); | |||||
| assertEquals('650-2', f.inputDigitAndRememberPosition('2')); | |||||
| assertEquals(5, f.getRememberedPosition()); | |||||
| assertEquals('650-25', f.inputDigit('5')); | |||||
| assertEquals(5, f.getRememberedPosition()); | |||||
| assertEquals('650-253', f.inputDigit('3')); | |||||
| assertEquals(5, f.getRememberedPosition()); | |||||
| assertEquals('650-253-', f.inputDigit('-')); | |||||
| assertEquals('650-253-2', f.inputDigit('2')); | |||||
| assertEquals('650-253-22', f.inputDigit('2')); | |||||
| assertEquals('650-253-222', f.inputDigit('2')); | |||||
| assertEquals('650-253-2222', f.inputDigit('2')); | |||||
| f.clear(); | |||||
| assertEquals('0', f.inputDigit('0')); | |||||
| assertEquals('01', f.inputDigit('1')); | |||||
| assertEquals('011', f.inputDigit('1')); | |||||
| assertEquals('0114', f.inputDigitAndRememberPosition('4')); | |||||
| assertEquals('01148', f.inputDigit('8')); | |||||
| assertEquals(4, f.getRememberedPosition()); | |||||
| assertEquals('011 48 8', f.inputDigit('8')); | |||||
| assertEquals(5, f.getRememberedPosition()); | |||||
| assertEquals('011 48 88', f.inputDigit('8')); | |||||
| assertEquals('011 48 881', f.inputDigit('1')); | |||||
| assertEquals('011 48 88 12', f.inputDigit('2')); | |||||
| assertEquals(5, f.getRememberedPosition()); | |||||
| assertEquals('011 48 88 123', f.inputDigit('3')); | |||||
| assertEquals('011 48 88 123 1', f.inputDigit('1')); | |||||
| assertEquals('011 48 88 123 12', f.inputDigit('2')); | |||||
| assertEquals('011 48 88 123 12 1', f.inputDigit('1')); | |||||
| assertEquals('011 48 88 123 12 12', f.inputDigit('2')); | |||||
| f.clear(); | |||||
| assertEquals('+', f.inputDigit('+')); | |||||
| assertEquals('+1', f.inputDigit('1')); | |||||
| assertEquals('+16', f.inputDigitAndRememberPosition('6')); | |||||
| assertEquals('+165', f.inputDigit('5')); | |||||
| assertEquals('+1650', f.inputDigit('0')); | |||||
| assertEquals(3, f.getRememberedPosition()); | |||||
| assertEquals('+1 650 2', f.inputDigit('2')); | |||||
| assertEquals(4, f.getRememberedPosition()); | |||||
| assertEquals('+1 650 25', f.inputDigit('5')); | |||||
| assertEquals('+1 650 253', f.inputDigitAndRememberPosition('3')); | |||||
| assertEquals('+1 650 253 2', f.inputDigit('2')); | |||||
| assertEquals('+1 650 253 22', f.inputDigit('2')); | |||||
| assertEquals('+1 650 253 222', f.inputDigit('2')); | |||||
| assertEquals(10, f.getRememberedPosition()); | |||||
| f.clear(); | |||||
| assertEquals('+', f.inputDigit('+')); | |||||
| assertEquals('+1', f.inputDigit('1')); | |||||
| assertEquals('+16', f.inputDigitAndRememberPosition('6')); | |||||
| assertEquals('+165', f.inputDigit('5')); | |||||
| assertEquals('+1650', f.inputDigit('0')); | |||||
| assertEquals(3, f.getRememberedPosition()); | |||||
| assertEquals('+1 650 2', f.inputDigit('2')); | |||||
| assertEquals(4, f.getRememberedPosition()); | |||||
| assertEquals('+1 650 25', f.inputDigit('5')); | |||||
| assertEquals('+1 650 253', f.inputDigit('3')); | |||||
| assertEquals('+1 650 253 2', f.inputDigit('2')); | |||||
| assertEquals('+1 650 253 22', f.inputDigit('2')); | |||||
| assertEquals('+1 650 253 222', f.inputDigit('2')); | |||||
| assertEquals('+1650253222;', f.inputDigit(';')); | |||||
| assertEquals(3, f.getRememberedPosition()); | |||||
| } | |||||
| function testAsYouTypeFormatterGBFixedLine() { | |||||
| /** @type {i18n.phonenumbers.AsYouTypeFormatter} */ | |||||
| var f = new i18n.phonenumbers.AsYouTypeFormatter('GB'); | |||||
| assertEquals('0', f.inputDigit('0')); | |||||
| assertEquals('02', f.inputDigit('2')); | |||||
| assertEquals('020', f.inputDigit('0')); | |||||
| assertEquals('0207', f.inputDigitAndRememberPosition('7')); | |||||
| assertEquals(4, f.getRememberedPosition()); | |||||
| assertEquals('02070', f.inputDigit('0')); | |||||
| assertEquals('020 703', f.inputDigit('3')); | |||||
| assertEquals(5, f.getRememberedPosition()); | |||||
| assertEquals('020 7031', f.inputDigit('1')); | |||||
| assertEquals('020 7031 3', f.inputDigit('3')); | |||||
| assertEquals('020 7031 30', f.inputDigit('0')); | |||||
| assertEquals('020 7031 300', f.inputDigit('0')); | |||||
| assertEquals('020 7031 3000', f.inputDigit('0')); | |||||
| } | |||||
| function testAsYouTypeFormatterGBTollFree() { | |||||
| /** @type {i18n.phonenumbers.AsYouTypeFormatter} */ | |||||
| var f = new i18n.phonenumbers.AsYouTypeFormatter('gb'); | |||||
| assertEquals('0', f.inputDigit('0')); | |||||
| assertEquals('08', f.inputDigit('8')); | |||||
| assertEquals('080', f.inputDigit('0')); | |||||
| assertEquals('0807', f.inputDigit('7')); | |||||
| assertEquals('08070', f.inputDigit('0')); | |||||
| assertEquals('080 703', f.inputDigit('3')); | |||||
| assertEquals('080 7031', f.inputDigit('1')); | |||||
| assertEquals('080 7031 3', f.inputDigit('3')); | |||||
| assertEquals('080 7031 30', f.inputDigit('0')); | |||||
| assertEquals('080 7031 300', f.inputDigit('0')); | |||||
| assertEquals('080 7031 3000', f.inputDigit('0')); | |||||
| } | |||||
| function testAsYouTypeFormatterGBPremiumRate() { | |||||
| /** @type {i18n.phonenumbers.AsYouTypeFormatter} */ | |||||
| var f = new i18n.phonenumbers.AsYouTypeFormatter('GB'); | |||||
| assertEquals('0', f.inputDigit('0')); | |||||
| assertEquals('09', f.inputDigit('9')); | |||||
| assertEquals('090', f.inputDigit('0')); | |||||
| assertEquals('0907', f.inputDigit('7')); | |||||
| assertEquals('09070', f.inputDigit('0')); | |||||
| assertEquals('090 703', f.inputDigit('3')); | |||||
| assertEquals('090 7031', f.inputDigit('1')); | |||||
| assertEquals('090 7031 3', f.inputDigit('3')); | |||||
| assertEquals('090 7031 30', f.inputDigit('0')); | |||||
| assertEquals('090 7031 300', f.inputDigit('0')); | |||||
| assertEquals('090 7031 3000', f.inputDigit('0')); | |||||
| } | |||||
| function testAsYouTypeFormatterNZMobile() { | |||||
| /** @type {i18n.phonenumbers.AsYouTypeFormatter} */ | |||||
| var f = new i18n.phonenumbers.AsYouTypeFormatter('NZ'); | |||||
| assertEquals('0', f.inputDigit('0')); | |||||
| assertEquals('02', f.inputDigit('2')); | |||||
| assertEquals('021', f.inputDigit('1')); | |||||
| assertEquals('0211', f.inputDigit('1')); | |||||
| assertEquals('02112', f.inputDigit('2')); | |||||
| // Note the unittest is using fake metadata which might produce non-ideal | |||||
| // results. | |||||
| assertEquals('02-112 3', f.inputDigit('3')); | |||||
| assertEquals('02-112 34', f.inputDigit('4')); | |||||
| assertEquals('02-112 345', f.inputDigit('5')); | |||||
| assertEquals('02-112 3456', f.inputDigit('6')); | |||||
| } | |||||
| function testAsYouTypeFormatterDE() { | |||||
| /** @type {i18n.phonenumbers.AsYouTypeFormatter} */ | |||||
| var f = new i18n.phonenumbers.AsYouTypeFormatter('DE'); | |||||
| assertEquals('0', f.inputDigit('0')); | |||||
| assertEquals('03', f.inputDigit('3')); | |||||
| assertEquals('030', f.inputDigit('0')); | |||||
| assertEquals('0301', f.inputDigit('1')); | |||||
| assertEquals('03012', f.inputDigit('2')); | |||||
| assertEquals('030 123', f.inputDigit('3')); | |||||
| assertEquals('030 1234', f.inputDigit('4')); | |||||
| } | |||||
| function testAsYouTypeFormatterAR() { | |||||
| /** @type {i18n.phonenumbers.AsYouTypeFormatter} */ | |||||
| var f = new i18n.phonenumbers.AsYouTypeFormatter('AR'); | |||||
| assertEquals('0', f.inputDigit('0')); | |||||
| assertEquals('01', f.inputDigit('1')); | |||||
| assertEquals('011', f.inputDigit('1')); | |||||
| assertEquals('0117', f.inputDigit('7')); | |||||
| assertEquals('01170', f.inputDigit('0')); | |||||
| assertEquals('011 703', f.inputDigit('3')); | |||||
| assertEquals('011 7031', f.inputDigit('1')); | |||||
| assertEquals('011 7031-3', f.inputDigit('3')); | |||||
| assertEquals('011 7031-30', f.inputDigit('0')); | |||||
| assertEquals('011 7031-300', f.inputDigit('0')); | |||||
| assertEquals('011 7031-3000', f.inputDigit('0')); | |||||
| } | |||||
| function testAsYouTypeFormatterARMobile() { | |||||
| /** @type {i18n.phonenumbers.AsYouTypeFormatter} */ | |||||
| var f = new i18n.phonenumbers.AsYouTypeFormatter('AR'); | |||||
| assertEquals('+', f.inputDigit('+')); | |||||
| assertEquals('+5', f.inputDigit('5')); | |||||
| assertEquals('+54', f.inputDigit('4')); | |||||
| assertEquals('+549', f.inputDigit('9')); | |||||
| assertEquals('+5491', f.inputDigit('1')); | |||||
| assertEquals('+54 911', f.inputDigit('1')); | |||||
| assertEquals('+54 9 11 2', f.inputDigit('2')); | |||||
| assertEquals('+54 9 11 23', f.inputDigit('3')); | |||||
| assertEquals('+54 9 11 231', f.inputDigit('1')); | |||||
| assertEquals('+54 9 11 2312', f.inputDigit('2')); | |||||
| assertEquals('+54 9 11 2312 1', f.inputDigit('1')); | |||||
| assertEquals('+54 9 11 2312 12', f.inputDigit('2')); | |||||
| assertEquals('+54 9 11 2312 123', f.inputDigit('3')); | |||||
| assertEquals('+54 9 11 2312 1234', f.inputDigit('4')); | |||||
| } | |||||
| function testAsYouTypeFormatterKR() { | |||||
| // +82 51 234 5678 | |||||
| /** @type {i18n.phonenumbers.AsYouTypeFormatter} */ | |||||
| var f = new i18n.phonenumbers.AsYouTypeFormatter('KR'); | |||||
| assertEquals('+', f.inputDigit('+')); | |||||
| assertEquals('+8', f.inputDigit('8')); | |||||
| assertEquals('+82', f.inputDigit('2')); | |||||
| assertEquals('+825', f.inputDigit('5')); | |||||
| assertEquals('+8251', f.inputDigit('1')); | |||||
| assertEquals('+82 512', f.inputDigit('2')); | |||||
| assertEquals('+82 51-23', f.inputDigit('3')); | |||||
| assertEquals('+82 51-234', f.inputDigit('4')); | |||||
| assertEquals('+82 51-234-5', f.inputDigit('5')); | |||||
| assertEquals('+82 51-234-56', f.inputDigit('6')); | |||||
| assertEquals('+82 51-234-567', f.inputDigit('7')); | |||||
| assertEquals('+82 51-234-5678', f.inputDigit('8')); | |||||
| // +82 2 531 5678 | |||||
| f.clear(); | |||||
| assertEquals('+', f.inputDigit('+')); | |||||
| assertEquals('+8', f.inputDigit('8')); | |||||
| assertEquals('+82', f.inputDigit('2')); | |||||
| assertEquals('+822', f.inputDigit('2')); | |||||
| assertEquals('+8225', f.inputDigit('5')); | |||||
| assertEquals('+82 253', f.inputDigit('3')); | |||||
| assertEquals('+82 2-531', f.inputDigit('1')); | |||||
| assertEquals('+82 2-531-5', f.inputDigit('5')); | |||||
| assertEquals('+82 2-531-56', f.inputDigit('6')); | |||||
| assertEquals('+82 2-531-567', f.inputDigit('7')); | |||||
| assertEquals('+82 2-531-5678', f.inputDigit('8')); | |||||
| // +82 2 3665 5678 | |||||
| f.clear(); | |||||
| assertEquals('+', f.inputDigit('+')); | |||||
| assertEquals('+8', f.inputDigit('8')); | |||||
| assertEquals('+82', f.inputDigit('2')); | |||||
| assertEquals('+822', f.inputDigit('2')); | |||||
| assertEquals('+8223', f.inputDigit('3')); | |||||
| assertEquals('+82 236', f.inputDigit('6')); | |||||
| assertEquals('+82 2-366', f.inputDigit('6')); | |||||
| assertEquals('+82 2-3665', f.inputDigit('5')); | |||||
| assertEquals('+82 2-3665-5', f.inputDigit('5')); | |||||
| assertEquals('+82 2-3665-56', f.inputDigit('6')); | |||||
| assertEquals('+82 2-3665-567', f.inputDigit('7')); | |||||
| assertEquals('+82 2-3665-5678', f.inputDigit('8')); | |||||
| // 02-114 : This is too short to format. Checking that there are no | |||||
| // side-effects. | |||||
| f.clear(); | |||||
| assertEquals('0', f.inputDigit('0')); | |||||
| assertEquals('02', f.inputDigit('2')); | |||||
| assertEquals('021', f.inputDigit('1')); | |||||
| assertEquals('0211', f.inputDigit('1')); | |||||
| assertEquals('02114', f.inputDigit('4')); | |||||
| // 02-1300 | |||||
| f.clear(); | |||||
| assertEquals('0', f.inputDigit('0')); | |||||
| assertEquals('02', f.inputDigit('2')); | |||||
| assertEquals('021', f.inputDigit('1')); | |||||
| assertEquals('0213', f.inputDigit('3')); | |||||
| assertEquals('02130', f.inputDigit('0')); | |||||
| assertEquals('02-1300', f.inputDigit('0')); | |||||
| // 011-456-7890 | |||||
| f.clear(); | |||||
| assertEquals('0', f.inputDigit('0')); | |||||
| assertEquals('01', f.inputDigit('1')); | |||||
| assertEquals('011', f.inputDigit('1')); | |||||
| assertEquals('0114', f.inputDigit('4')); | |||||
| assertEquals('01145', f.inputDigit('5')); | |||||
| assertEquals('011-456', f.inputDigit('6')); | |||||
| assertEquals('011-456-7', f.inputDigit('7')); | |||||
| assertEquals('011-456-78', f.inputDigit('8')); | |||||
| assertEquals('011-456-789', f.inputDigit('9')); | |||||
| assertEquals('011-456-7890', f.inputDigit('0')); | |||||
| // 011-9876-7890 | |||||
| f.clear(); | |||||
| assertEquals('0', f.inputDigit('0')); | |||||
| assertEquals('01', f.inputDigit('1')); | |||||
| assertEquals('011', f.inputDigit('1')); | |||||
| assertEquals('0119', f.inputDigit('9')); | |||||
| assertEquals('01198', f.inputDigit('8')); | |||||
| assertEquals('011-987', f.inputDigit('7')); | |||||
| assertEquals('011-9876', f.inputDigit('6')); | |||||
| assertEquals('011-9876-7', f.inputDigit('7')); | |||||
| assertEquals('011-9876-78', f.inputDigit('8')); | |||||
| assertEquals('011-9876-789', f.inputDigit('9')); | |||||
| assertEquals('011-9876-7890', f.inputDigit('0')); | |||||
| } | |||||
| @ -0,0 +1,125 @@ | |||||
| <!DOCTYPE html> | |||||
| <html> | |||||
| <!-- | |||||
| Copyright (C) 2010 Google Inc. | |||||
| Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| you may not use this file except in compliance with the License. | |||||
| You may obtain a copy of the License at | |||||
| http://www.apache.org/licenses/LICENSE-2.0 | |||||
| Unless required by applicable law or agreed to in writing, software | |||||
| distributed under the License is distributed on an "AS-IS" BASIS, | |||||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| See the License for the specific language governing permissions and | |||||
| limitations under the License. | |||||
| --> | |||||
| <!-- | |||||
| Author: Nikolaos Trogkanis | |||||
| --> | |||||
| <head> | |||||
| <title>Phone Number Parser Demo</title> | |||||
| <script src="../../../../closure-library/closure/goog/base.js"></script> | |||||
| <script> | |||||
| goog.require('goog.dom'); | |||||
| goog.require('goog.json'); | |||||
| goog.require('goog.proto2.ObjectSerializer'); | |||||
| goog.require('goog.string.StringBuffer'); | |||||
| </script> | |||||
| <script src="phonemetadata.pb.js"></script> | |||||
| <script src="phonenumber.pb.js"></script> | |||||
| <script src="metadata.js"></script> | |||||
| <script src="phonenumberutil.js"></script> | |||||
| </head> | |||||
| <body> | |||||
| <script> | |||||
| function phoneNumberParser() { | |||||
| var $ = goog.dom.getElement; | |||||
| var phoneNumber = $('phoneNumber').value; | |||||
| var regionCode = $('defaultCountry').value; | |||||
| var output = new goog.string.StringBuffer(); | |||||
| try { | |||||
| var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance(); | |||||
| var number = phoneUtil.parse(phoneNumber, regionCode); | |||||
| output.append('****Parsing Result:****\n'); | |||||
| output.append(goog.json.serialize(new goog.proto2.ObjectSerializer( | |||||
| goog.proto2.ObjectSerializer.KeyOption.NAME).serialize(number))); | |||||
| output.append('\n\n****Validation Results:****'); | |||||
| output.append('\nResult from isValidNumber(): '); | |||||
| output.append(phoneUtil.isValidNumber(number)); | |||||
| output.append('\nResult from isValidNumberForRegion(): ') | |||||
| .append(phoneUtil.isValidNumberForRegion(number, regionCode)); | |||||
| output.append('\nResult from isPossibleNumber(): ') | |||||
| .append(phoneUtil.isPossibleNumber(number)); | |||||
| output.append('\nResult from getNumberType(): '); | |||||
| var PNT = i18n.phonenumbers.PhoneNumberType; | |||||
| switch(phoneUtil.getNumberType(number)) { | |||||
| case PNT.FIXED_LINE: | |||||
| output.append('FIXED_LINE'); | |||||
| break; | |||||
| case PNT.MOBILE: | |||||
| output.append('MOBILE'); | |||||
| break; | |||||
| case PNT.FIXED_LINE_OR_MOBILE: | |||||
| output.append('FIXED_LINE_OR_MOBILE'); | |||||
| break; | |||||
| case PNT.TOLL_FREE: | |||||
| output.append('TOLL_FREE'); | |||||
| break; | |||||
| case PNT.PREMIUM_RATE: | |||||
| output.append('PREMIUM_RATE'); | |||||
| break; | |||||
| case PNT.SHARED_COST: | |||||
| output.append('SHARED_COST'); | |||||
| break; | |||||
| case PNT.VOIP: | |||||
| output.append('VOIP'); | |||||
| break; | |||||
| case PNT.PERSONAL_NUMBER: | |||||
| output.append('PERSONAL_NUMBER'); | |||||
| break; | |||||
| case PNT.UNKNOWN: | |||||
| output.append('UNKNOWN'); | |||||
| break; | |||||
| } | |||||
| var PNF = i18n.phonenumbers.PhoneNumberFormat; | |||||
| output.append('\n\n****Formatting Results:**** '); | |||||
| output.append('\nE164 format: '); | |||||
| output.append(phoneUtil.format(number, PNF.E164)); | |||||
| output.append('\nInternational format: '); | |||||
| output.append(phoneUtil.format(number, PNF.INTERNATIONAL)); | |||||
| output.append('\nNational format: '); | |||||
| output.append(phoneUtil.format(number, PNF.NATIONAL)); | |||||
| output.append('\nOut-of-country format from US: '); | |||||
| output.append(phoneUtil.formatOutOfCountryCallingNumber(number, 'US')); | |||||
| } catch (e) { | |||||
| output.append('\n' + e); | |||||
| } | |||||
| $('output').value = output.toString(); | |||||
| return false; | |||||
| } | |||||
| </script> | |||||
| <h2>Phone Number Parser Demo</h2> | |||||
| <form> | |||||
| <p> | |||||
| Specify a Phone Number: | |||||
| <input type="text" name="phoneNumber" id="phoneNumber" size="25" /> | |||||
| </p> | |||||
| <p> | |||||
| Specify a Default Country: | |||||
| <input type="text" name="defaultCountry" id="defaultCountry" size="2" /> | |||||
| (ISO 3166-1 two-letter country code) | |||||
| </p> | |||||
| <input type="submit" value="Submit" onclick="return phoneNumberParser();" /> | |||||
| <input type="reset" value="Reset" /> | |||||
| <p> | |||||
| <textarea id="output" rows="15" cols="60"></textarea> | |||||
| </p> | |||||
| </form> | |||||
| </body> | |||||
| </html> | |||||
| @ -0,0 +1,248 @@ | |||||
| // Copyright (C) 2010 Google Inc. | |||||
| // | |||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| // you may not use this file except in compliance with the License. | |||||
| // You may obtain a copy of the License at | |||||
| // | |||||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||||
| // | |||||
| // Unless required by applicable law or agreed to in writing, software | |||||
| // distributed under the License is distributed on an "AS-IS" BASIS, | |||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| // See the License for the specific language governing permissions and | |||||
| // limitations under the License. | |||||
| /** | |||||
| * @fileoverview Generated metadata for file | |||||
| * PhoneNumberMetaDataForTesting.xml | |||||
| * @author Nikolaos Trogkanis | |||||
| */ | |||||
| goog.provide('i18n.phonenumbers.metadata'); | |||||
| /** | |||||
| * A mapping from a country code to the region codes which denote the | |||||
| * country/region represented by that country code. In the case of multiple | |||||
| * countries sharing a calling code, such as the NANPA countries, the one | |||||
| * indicated with 'isMainCountryForCode' in the metadata should be first. | |||||
| * @type {Object.<number, Array.<string>>} | |||||
| */ | |||||
| i18n.phonenumbers.metadata.countryCodeToRegionCodeMap = { | |||||
| 1: ['US','BS'], | |||||
| 39: ['IT'], | |||||
| 44: ['GB'], | |||||
| 48: ['PL'], | |||||
| 49: ['DE'], | |||||
| 52: ['MX'], | |||||
| 54: ['AR'], | |||||
| 61: ['AU'], | |||||
| 64: ['NZ'], | |||||
| 65: ['SG'], | |||||
| 82: ['KR'], | |||||
| 262: ['RE','YT'], | |||||
| 376: ['AD'] | |||||
| }; | |||||
| /** | |||||
| * A mapping from a region code to the PhoneMetadata for that region. | |||||
| * @type {Object.<string, Array>} | |||||
| */ | |||||
| i18n.phonenumbers.metadata.countryToMetadata = { | |||||
| "AD": [,[] | |||||
| ,[] | |||||
| ,[] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"AD",376,"00",,,,,,,1] | |||||
| , | |||||
| "AR": [,[,,"[1-3689]\\d{9,10}","\\d{6,11}"] | |||||
| ,[,,"[1-3]\\d{9}","\\d{6,10}"] | |||||
| ,[,,"9\\d{10}|[1-3]\\d{9}","\\d{10,11}"] | |||||
| ,[,,"80\\d{8}","\\d{10}"] | |||||
| ,[,,"6(0\\d|10)\\d{7}","\\d{10}"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"AR",54,"00","0",,,"0(?:(11|343|3715)15)?","9$1",,,[[,"(\\d{2})(\\d{4})(\\d{4})","$1 $2-$3","11","0$1",""], | |||||
| [,"(\\d{4})(\\d{2})(\\d{4})","$1 $2-$3","1[02-9]|[23]","0$1",""], | |||||
| [,"9(11)(\\d{4})(\\d{4})","$1 15 $2-$3","911","0$1",""], | |||||
| [,"9(\\d{4})(\\d{2})(\\d{4})","$1 $2-$3","9(?:1[02-9]|[23])","0$1","$1 $CC"], | |||||
| [,"(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3","[68]","0$1",""]] | |||||
| ,[[,"(\\d{2})(\\d{4})(\\d{4})","$1 $2-$3","11",,""], | |||||
| [,"(\\d{4})(\\d{2})(\\d{4})","$1 $2-$3","1[02-9]|[23]",,""], | |||||
| [,"(9)(11)(\\d{4})(\\d{4})","$1 $2 $3 $4","911",,""], | |||||
| [,"(9)(\\d{4})(\\d{2})(\\d{4})","$1 $2 $3 $4","9(?:1[02-9]|[23])",,""], | |||||
| [,"(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3","[68]",,""]]] | |||||
| , | |||||
| "AU": [,[,,"[1-578]\\d{4,14}","\\d{5,15}"] | |||||
| ,[,,"[2378]\\d{8}","\\d{9}"] | |||||
| ,[,,"4\\d{8}","\\d{9}"] | |||||
| ,[,,"1800\\d{6}","\\d{10}"] | |||||
| ,[,,"190[0126]\\d{6}","\\d{10}"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"AU",61,"001[12]","0",,,"0",,"0011",,[[,"(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3","1","$1",""], | |||||
| [,"(\\d{1})(\\d{4})(\\d{4})","$1 $2 $3","[2-478]","0$1",""]]] | |||||
| , | |||||
| "BS": [,[,,"(242|8(00|66|77|88)|900)\\d{7}","\\d{7,10}"] | |||||
| ,[,,"242(?:3(?:02|[236][1-9]|4[0-24-9]|5[0-68]|7[3-57]|9[2-5])|4(?:2[237]|51|64|77)|502|636|702)\\d{4}","\\d{7,10}"] | |||||
| ,[,,"242(357|359|457|557)\\d{4}","\\d{10}"] | |||||
| ,[,,"8(00|66|77|88)\\d{7}","\\d{10}"] | |||||
| ,[,,"900\\d{7}","\\d{10}"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"BS",1,"011",,,,,,,,[[,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",,"",""]]] | |||||
| , | |||||
| "DE": [,[,,"\\d{4,14}","\\d{2,14}"] | |||||
| ,[,,"(?:[24-6]\\d{2}|3[03-9]\\d|[789](?:[1-9]\\d|0[2-9]))\\d{3,8}","\\d{2,14}",,,"30123456"] | |||||
| ,[,,"1(5\\d{9}|7\\d{8}|6[02]\\d{8}|63\\d{7})","\\d{10,11}"] | |||||
| ,[,,"800\\d{7}","\\d{10}"] | |||||
| ,[,,"900([135]\\d{6}|9\\d{7})","\\d{10,11}"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"DE",49,"00","0",,,"0",,,,[[,"(\\d{3})(\\d{3,8})","$1 $2","2|3[3-9]|906|[4-9][1-9]1","0$1",""], | |||||
| [,"(\\d{2})(\\d{4,9})","$1 $2","[34]0|[68]9","0$1",""], | |||||
| [,"([4-9]\\d{3})(\\d{2,7})","$1 $2","[4-9]","0$1",""], | |||||
| [,"(\\d{3})(\\d{1})(\\d{6})","$1 $2 $3","800","0$1",""], | |||||
| [,"(\\d{3})(\\d{3})(d{4})","$1 $2 $3","900[135]","0$1",""], | |||||
| [,"(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3","9009","0$1",""]]] | |||||
| , | |||||
| "GB": [,[,,"\\d{10}","\\d{6,10}"] | |||||
| ,[,,"[1-6]\\d{9}","\\d{6,10}"] | |||||
| ,[,,"7[1-57-9]\\d{8}","\\d{10}"] | |||||
| ,[,,"80\\d{8}","\\d{10}"] | |||||
| ,[,,"9[018]\\d{8}","\\d{10}"] | |||||
| ,[,,"8(?:4[3-5]|7[0-2])\\d{7}","\\d{10}"] | |||||
| ,[,,"70\\d{8}","\\d{10}"] | |||||
| ,[,,"56\\d{8}","\\d{10}"] | |||||
| ,"GB",44,"00","0",,,"0",,,,[[,"(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3","[1-59]|[78]0","(0$1)",""], | |||||
| [,"(\\d)(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4","6","(0$1)",""], | |||||
| [,"(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3","7[1-57-9]","(0$1)",""], | |||||
| [,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3","8[47]","(0$1)",""]]] | |||||
| , | |||||
| "IT": [,[,,"[0389]\\d{5,10}","\\d{6,11}"] | |||||
| ,[,,"0\\d{9,10}","\\d{10,11}"] | |||||
| ,[,,"3\\d{8,9}","\\d{9,10}"] | |||||
| ,[,,"80(?:0\\d{6}|3\\d{3})","\\d{6,9}"] | |||||
| ,[,,"89(?:2\\d{3}|9\\d{6})","\\d{6,9}"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"IT",39,"00",,,,,,,,[[,"(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3","0[26]","",""], | |||||
| [,"(\\d{3})(\\d{4})(\\d{3,4})","$1 $2 $3","0[13-57-9]","",""], | |||||
| [,"(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3","3","",""], | |||||
| [,"(\\d{3})(\\d{3,6})","$1 $2","8","",""]]] | |||||
| , | |||||
| "KR": [,[,,"[1-79]\\d{3,9}|8\\d{8}","\\d{4,10}"] | |||||
| ,[,,"[1-79]\\d{3,9}|8\\d{8}","\\d{4,10}"] | |||||
| ,[,,"[1-79]\\d{3,9}|8\\d{8}","\\d{4,10}"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"KR",82,"00(?:[124-68]|[37]\\d{2})","0",,,"0(?:8[1-46-8]|85\\d{2})?",,,1,[[,"(\\d{2})(\\d{4})(\\d{4})","$1-$2-$3","1(?:0|1[19]|[69]9|5(?:44|59|8))|[57]0","0$1",""], | |||||
| [,"(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3","1(?:[169][2-8]|[78]|5(?:[1-3]|4[56]))|[68]0|[3-9][1-9][2-9]","0$1",""], | |||||
| [,"(\\d{3})(\\d)(\\d{4})","$1-$2-$3","1312","0$1",""], | |||||
| [,"(\\d{3})(\\d{2})(\\d{4})","$1-$2-$3","131[13-9]","0$1",""], | |||||
| [,"(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3","13[2-9]","0$1",""], | |||||
| [,"(\\d{2})(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3-$4","30","0$1",""], | |||||
| [,"(\\d)(\\d{4})(\\d{4})","$1-$2-$3","2(?:[26]|3(?:01|1[45]|2[17-9]|39|4|6[67]|7[078]))","0$1",""], | |||||
| [,"(\\d)(\\d{3})(\\d{4})","$1-$2-$3","2(?:3(?:0[02-9]|1[0-36-9]|2[02-6]|3[0-8]|6[0-589]|7[1-69]|[589])|[457-9])","0$1",""], | |||||
| [,"(\\d)(\\d{3})","$1-$2","21(?:[0-247-9]|3[124]|6[1269])","0$1",""], | |||||
| [,"(\\d)(\\d{4})","$1-$2","21(?:3[035-9]|6[03-578])","0$1",""], | |||||
| [,"(\\d{2})(\\d{3})","$1-$2","[3-9][1-9]1(?:[0-247-9]|3[124]|6[1269])","0$1",""], | |||||
| [,"(\\d{2})(\\d{4})","$1-$2","[3-9][1-9]1(?:3[035-9]|6[03-578])","0$1",""]]] | |||||
| , | |||||
| "MX": [,[,,"[1-9]\\d{9,10}","\\d{7,11}"] | |||||
| ,[,,"[2-9]\\d{9}","\\d{7,10}"] | |||||
| ,[,,"1\\d{10}","\\d{11}"] | |||||
| ,[,,"800\\d{7}","\\d{10}"] | |||||
| ,[,,"900\\d{7}","\\d{10}"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"MX",52,"00","01",,,"01|04[45](\\d{10})","1$1",,,[[,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3","[89]00","",""], | |||||
| [,"(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3","33|55|81","",""], | |||||
| [,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3","[2467]|3[0-24-9]|5[0-46-9]|8[2-9]|9[1-9]","",""], | |||||
| [,"1(\\d{2})(\\d{4})(\\d{4})","045 $1 $2 $3","1(?:33|55|81)","",""], | |||||
| [,"1(\\d{3})(\\d{3})(\\d{4})","045 $1 $2 $3","1(?:[124579]|3[0-24-9]|5[0-46-9]|8[02-9])","",""]] | |||||
| ,[[,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3","[89]00",,""], | |||||
| [,"(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3","33|55|81",,""], | |||||
| [,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3","[2467]|3[0-24-9]|5[0-46-9]|8[2-9]|9[1-9]",,""], | |||||
| [,"(1)(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3 $4","1(?:33|55|81)",,""], | |||||
| [,"(1)(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3 $4","1(?:[124579]|3[0-24-9]|5[0-46-9]|8[02-9])",,""]]] | |||||
| , | |||||
| "NZ": [,[,,"[2-9]\\d{7,9}","\\d{7,10}"] | |||||
| ,[,,"24099\\d{3}|(?:3[2-79]|[479][2-689]|6[235-9])\\d{6}","\\d{7,8}"] | |||||
| ,[,,"2(?:[027]\\d{7}|9\\d{6,7}|1(?:0\\d{5,7}|[12]\\d{5,6}|[3-9]\\d{5})|4[1-9]\\d{6}|8\\d{7,8})","\\d{8,10}"] | |||||
| ,[,,"800\\d{6,7}","\\d{9,10}"] | |||||
| ,[,,"900\\d{6,7}","\\d{9,10}"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"NZ",64,"00","0",,,"0",,,,[[,"(\\d)(\\d{3})(\\d{4})","$1-$2 $3","24|[34679]","0$1",""], | |||||
| [,"(\\d)(\\d{3})(\\d{3,5})","$1-$2 $3","2[179]","0$1",""], | |||||
| [,"(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3","[89]","0$1",""]]] | |||||
| , | |||||
| "PL": [,[,,"[1-9]\\d{8}","\\d{9}"] | |||||
| ,[,,"[1-9]\\d{8}","\\d{9}"] | |||||
| ,[,,"(?:5[01]|6[069]|7[289]|88)\\d{7}","\\d{9}"] | |||||
| ,[,,"800\\d{6}","\\d{9}"] | |||||
| ,[,,"70\\d{7}","\\d{9}"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"PL",48,"0~0","0",,,"0",,,,[[,"(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",,"0$1",""]]] | |||||
| , | |||||
| "RE": [,[,,"[268]\\d{8}","\\d{9}"] | |||||
| ,[,,"262\\d{6}","\\d{9}",,,"262161234"] | |||||
| ,[,,"6(?:9[23]|47)\\d{6}","\\d{9}",,,"692123456"] | |||||
| ,[,,"80\\d{7}","\\d{9}",,,"801234567"] | |||||
| ,[,,"8(?:1[01]|2[0156]|84|9[0-37-9])\\d{6}","\\d{9}",,,"810123456"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"RE",262,"00","0",,,"0",,,,[[,"([268]\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",,"0$1",""]] | |||||
| ,,,,"262|6(?:9[23]|47)|8"] | |||||
| , | |||||
| "SG": [,[,,"[13689]\\d{7,10}","\\d{8,11}"] | |||||
| ,[,,"[36]\\d{7}","\\d{8}"] | |||||
| ,[,,"[89]\\d{7}","\\d{8}"] | |||||
| ,[,,"1?800\\d{7}","\\d{10,11}"] | |||||
| ,[,,"1900\\d{7}","\\d{11}"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"SG",65,"0[0-3][0-9]",,,,,,,,[[,"(\\d{4})(\\d{4})","$1 $2","[369]|8[1-9]","",""], | |||||
| [,"(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3","1[89]","",""], | |||||
| [,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3","800","",""]]] | |||||
| , | |||||
| "US": [,[,,"[13-9]\\d{9}|2[0-35-9]\\d{8}","\\d{7,10}",,,"1234567890"] | |||||
| ,[,,"[13-9]\\d{9}|2[0-35-9]\\d{8}","\\d{7,10}",,,"1234567890"] | |||||
| ,[,,"[13-9]\\d{9}|2[0-35-9]\\d{8}","\\d{7,10}",,,"1234567890"] | |||||
| ,[,,"8(00|66|77|88)\\d{7}","\\d{10}",,,"1234567890"] | |||||
| ,[,,"900\\d{7}","\\d{10}",,,"1234567890"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"US",1,"011",," extn. ",,,,,1,[[,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",,"",""], | |||||
| [,"(\\d{3})(\\d{4})","$1 $2",,"",""]] | |||||
| ,,,1] | |||||
| , | |||||
| "YT": [,[,,"[268]\\d{8}","\\d{9}"] | |||||
| ,[,,"2696[0-4]\\d{4}","\\d{9}",,,"269601234"] | |||||
| ,[,,"639\\d{6}","\\d{9}",,,"639123456"] | |||||
| ,[,,"80\\d{7}","\\d{9}",,,"801234567"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,[,,"NA","NA"] | |||||
| ,"YT",262,"00","0",,,"0",,,,,,,,"269|639"] | |||||
| }; | |||||
| @ -0,0 +1,405 @@ | |||||
| // Protocol Buffer 2 Copyright 2008 Google Inc | |||||
| // All other code copyright its respective owners(s). | |||||
| // | |||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| // you may not use this file except in compliance with the License. | |||||
| // You may obtain a copy of the License at | |||||
| // | |||||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||||
| // | |||||
| // Unless required by applicable law or agreed to in writing, software | |||||
| // distributed under the License is distributed on an "AS-IS" BASIS, | |||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| // See the License for the specific language governing permissions and | |||||
| // limitations under the License. | |||||
| /** | |||||
| * @fileoverview Generated Protocol Buffer code for file | |||||
| * phonenumber.proto. | |||||
| */ | |||||
| goog.provide('i18n.phonenumbers.PhoneNumber'); | |||||
| goog.provide('i18n.phonenumbers.PhoneNumber.CountryCodeSource'); | |||||
| goog.require('goog.proto2.Message'); | |||||
| /** | |||||
| * Message PhoneNumber. | |||||
| * @constructor | |||||
| * @extends {goog.proto2.Message} | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber = function() { | |||||
| goog.proto2.Message.apply(this); | |||||
| }; | |||||
| goog.inherits(i18n.phonenumbers.PhoneNumber, goog.proto2.Message); | |||||
| /** | |||||
| * Gets the value of the country_code field. | |||||
| * @return {?number} The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.getCountryCode = function() { | |||||
| return /** @type {?number} */ (this.get$Value(1)); | |||||
| }; | |||||
| /** | |||||
| * Gets the value of the country_code field or the default value if not set. | |||||
| * @return {number} The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.getCountryCodeOrDefault = function() { | |||||
| return /** @type {number} */ (this.get$ValueOrDefault(1)); | |||||
| }; | |||||
| /** | |||||
| * Sets the value of the country_code field. | |||||
| * @param {number} value The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.setCountryCode = function(value) { | |||||
| this.set$Value(1, /** @type {Object} */ (value)); | |||||
| }; | |||||
| /** | |||||
| * Returns whether the country_code field has a value. | |||||
| * @return {boolean} true if the field has a value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.hasCountryCode = function() { | |||||
| return this.has$Value(1); | |||||
| }; | |||||
| /** | |||||
| * Gets the number of values in the country_code field. | |||||
| * @return {number} | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.countryCodeCount = function() { | |||||
| return this.count$Values(1); | |||||
| }; | |||||
| /** | |||||
| * Clears the values in the country_code field. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.clearCountryCode = function() { | |||||
| this.clear$Field(1); | |||||
| }; | |||||
| /** | |||||
| * Gets the value of the national_number field. | |||||
| * @return {?number} The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.getNationalNumber = function() { | |||||
| return /** @type {?number} */ (this.get$Value(2)); | |||||
| }; | |||||
| /** | |||||
| * Gets the value of the national_number field or the default value if not set. | |||||
| * @return {number} The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.getNationalNumberOrDefault = function() { | |||||
| return /** @type {number} */ (this.get$ValueOrDefault(2)); | |||||
| }; | |||||
| /** | |||||
| * Sets the value of the national_number field. | |||||
| * @param {number} value The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.setNationalNumber = function(value) { | |||||
| this.set$Value(2, /** @type {Object} */ (value)); | |||||
| }; | |||||
| /** | |||||
| * Returns whether the national_number field has a value. | |||||
| * @return {boolean} true if the field has a value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.hasNationalNumber = function() { | |||||
| return this.has$Value(2); | |||||
| }; | |||||
| /** | |||||
| * Gets the number of values in the national_number field. | |||||
| * @return {number} | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.nationalNumberCount = function() { | |||||
| return this.count$Values(2); | |||||
| }; | |||||
| /** | |||||
| * Clears the values in the national_number field. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.clearNationalNumber = function() { | |||||
| this.clear$Field(2); | |||||
| }; | |||||
| /** | |||||
| * Gets the value of the extension field. | |||||
| * @return {?string} The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.getExtension = function() { | |||||
| return /** @type {?string} */ (this.get$Value(3)); | |||||
| }; | |||||
| /** | |||||
| * Gets the value of the extension field or the default value if not set. | |||||
| * @return {string} The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.getExtensionOrDefault = function() { | |||||
| return /** @type {string} */ (this.get$ValueOrDefault(3)); | |||||
| }; | |||||
| /** | |||||
| * Sets the value of the extension field. | |||||
| * @param {string} value The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.setExtension = function(value) { | |||||
| this.set$Value(3, /** @type {Object} */ (value)); | |||||
| }; | |||||
| /** | |||||
| * Returns whether the extension field has a value. | |||||
| * @return {boolean} true if the field has a value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.hasExtension = function() { | |||||
| return this.has$Value(3); | |||||
| }; | |||||
| /** | |||||
| * Gets the number of values in the extension field. | |||||
| * @return {number} | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.extensionCount = function() { | |||||
| return this.count$Values(3); | |||||
| }; | |||||
| /** | |||||
| * Clears the values in the extension field. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.clearExtension = function() { | |||||
| this.clear$Field(3); | |||||
| }; | |||||
| /** | |||||
| * Gets the value of the italian_leading_zero field. | |||||
| * @return {?boolean} The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.getItalianLeadingZero = function() { | |||||
| return /** @type {?boolean} */ (this.get$Value(4)); | |||||
| }; | |||||
| /** | |||||
| * Gets the value of the italian_leading_zero field or the default value if not set. | |||||
| * @return {boolean} The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.getItalianLeadingZeroOrDefault = function() { | |||||
| return /** @type {boolean} */ (this.get$ValueOrDefault(4)); | |||||
| }; | |||||
| /** | |||||
| * Sets the value of the italian_leading_zero field. | |||||
| * @param {boolean} value The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.setItalianLeadingZero = function(value) { | |||||
| this.set$Value(4, /** @type {Object} */ (value)); | |||||
| }; | |||||
| /** | |||||
| * Returns whether the italian_leading_zero field has a value. | |||||
| * @return {boolean} true if the field has a value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.hasItalianLeadingZero = function() { | |||||
| return this.has$Value(4); | |||||
| }; | |||||
| /** | |||||
| * Gets the number of values in the italian_leading_zero field. | |||||
| * @return {number} | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.italianLeadingZeroCount = function() { | |||||
| return this.count$Values(4); | |||||
| }; | |||||
| /** | |||||
| * Clears the values in the italian_leading_zero field. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.clearItalianLeadingZero = function() { | |||||
| this.clear$Field(4); | |||||
| }; | |||||
| /** | |||||
| * Gets the value of the raw_input field. | |||||
| * @return {?string} The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.getRawInput = function() { | |||||
| return /** @type {?string} */ (this.get$Value(5)); | |||||
| }; | |||||
| /** | |||||
| * Gets the value of the raw_input field or the default value if not set. | |||||
| * @return {string} The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.getRawInputOrDefault = function() { | |||||
| return /** @type {string} */ (this.get$ValueOrDefault(5)); | |||||
| }; | |||||
| /** | |||||
| * Sets the value of the raw_input field. | |||||
| * @param {string} value The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.setRawInput = function(value) { | |||||
| this.set$Value(5, /** @type {Object} */ (value)); | |||||
| }; | |||||
| /** | |||||
| * Returns whether the raw_input field has a value. | |||||
| * @return {boolean} true if the field has a value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.hasRawInput = function() { | |||||
| return this.has$Value(5); | |||||
| }; | |||||
| /** | |||||
| * Gets the number of values in the raw_input field. | |||||
| * @return {number} | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.rawInputCount = function() { | |||||
| return this.count$Values(5); | |||||
| }; | |||||
| /** | |||||
| * Clears the values in the raw_input field. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.clearRawInput = function() { | |||||
| this.clear$Field(5); | |||||
| }; | |||||
| /** | |||||
| * Gets the value of the country_code_source field. | |||||
| * @return {?i18n.phonenumbers.PhoneNumber.CountryCodeSource} The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.getCountryCodeSource = function() { | |||||
| return /** @type {?i18n.phonenumbers.PhoneNumber.CountryCodeSource} */ (this.get$Value(6)); | |||||
| }; | |||||
| /** | |||||
| * Gets the value of the country_code_source field or the default value if not set. | |||||
| * @return {i18n.phonenumbers.PhoneNumber.CountryCodeSource} The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.getCountryCodeSourceOrDefault = function() { | |||||
| return /** @type {i18n.phonenumbers.PhoneNumber.CountryCodeSource} */ (this.get$ValueOrDefault(6)); | |||||
| }; | |||||
| /** | |||||
| * Sets the value of the country_code_source field. | |||||
| * @param {i18n.phonenumbers.PhoneNumber.CountryCodeSource} value The value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.setCountryCodeSource = function(value) { | |||||
| this.set$Value(6, /** @type {Object} */ (value)); | |||||
| }; | |||||
| /** | |||||
| * Returns whether the country_code_source field has a value. | |||||
| * @return {boolean} true if the field has a value. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.hasCountryCodeSource = function() { | |||||
| return this.has$Value(6); | |||||
| }; | |||||
| /** | |||||
| * Gets the number of values in the country_code_source field. | |||||
| * @return {number} | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.countryCodeSourceCount = function() { | |||||
| return this.count$Values(6); | |||||
| }; | |||||
| /** | |||||
| * Clears the values in the country_code_source field. | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.prototype.clearCountryCodeSource = function() { | |||||
| this.clear$Field(6); | |||||
| }; | |||||
| /** | |||||
| * Enumeration CountryCodeSource. | |||||
| * @enum {number} | |||||
| */ | |||||
| i18n.phonenumbers.PhoneNumber.CountryCodeSource = { | |||||
| FROM_NUMBER_WITH_PLUS_SIGN : 1, | |||||
| FROM_NUMBER_WITH_IDD : 5, | |||||
| FROM_NUMBER_WITHOUT_PLUS_SIGN : 10, | |||||
| FROM_DEFAULT_COUNTRY : 20 | |||||
| }; | |||||
| goog.proto2.Message.set$Metadata(i18n.phonenumbers.PhoneNumber, { | |||||
| 0 : { | |||||
| name: 'PhoneNumber', | |||||
| fullName: 'i18n.phonenumbers.PhoneNumber' | |||||
| }, | |||||
| '1' : { | |||||
| name: 'country_code', | |||||
| required: true, | |||||
| fieldType: goog.proto2.Message.FieldType.INT32, | |||||
| type: Number | |||||
| }, | |||||
| '2' : { | |||||
| name: 'national_number', | |||||
| required: true, | |||||
| fieldType: goog.proto2.Message.FieldType.UINT64, | |||||
| type: Number | |||||
| }, | |||||
| '3' : { | |||||
| name: 'extension', | |||||
| fieldType: goog.proto2.Message.FieldType.STRING, | |||||
| type: String | |||||
| }, | |||||
| '4' : { | |||||
| name: 'italian_leading_zero', | |||||
| fieldType: goog.proto2.Message.FieldType.BOOL, | |||||
| type: Boolean | |||||
| }, | |||||
| '5' : { | |||||
| name: 'raw_input', | |||||
| fieldType: goog.proto2.Message.FieldType.STRING, | |||||
| type: String | |||||
| }, | |||||
| '6' : { | |||||
| name: 'country_code_source', | |||||
| fieldType: goog.proto2.Message.FieldType.ENUM, | |||||
| defaultValue: i18n.phonenumbers.PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN, | |||||
| type: i18n.phonenumbers.PhoneNumber.CountryCodeSource | |||||
| }}); | |||||
| @ -0,0 +1,35 @@ | |||||
| <!DOCTYPE html> | |||||
| <html> | |||||
| <!-- | |||||
| Copyright (C) 2010 Google Inc. | |||||
| Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| you may not use this file except in compliance with the License. | |||||
| You may obtain a copy of the License at | |||||
| http://www.apache.org/licenses/LICENSE-2.0 | |||||
| Unless required by applicable law or agreed to in writing, software | |||||
| distributed under the License is distributed on an "AS-IS" BASIS, | |||||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| See the License for the specific language governing permissions and | |||||
| limitations under the License. | |||||
| --> | |||||
| <!-- | |||||
| Author: Nikolaos Trogkanis | |||||
| --> | |||||
| <head> | |||||
| <title>libphonenumber Unit Tests - i18n.phonenumbers - phonenumberutil.js</title> | |||||
| <script src="../../../../closure-library/closure/goog/base.js"></script> | |||||
| <script> | |||||
| goog.require('goog.proto2.Message'); | |||||
| </script> | |||||
| <script src="phonemetadata.pb.js"></script> | |||||
| <script src="phonenumber.pb.js"></script> | |||||
| <script src="metadatafortesting.js"></script> | |||||
| <script src="phonenumberutil.js"></script> | |||||
| <script src="phonenumberutil_test.js"></script> | |||||
| </head> | |||||
| <body> | |||||
| </body> | |||||
| </html> | |||||