4

I am trying to use Google's libphonenumber library in my project. I am trying to validate a phone number input using the javascript version, but it is giving me a "goog is not defined" error. I am very new to javascript andI have already spent a day searching for an answer and couldn't find one. The error is in the phonenumberutil.js on the very first line where it says

goog.provide('i18n.phonenumbers.Error');

This library needs the closure library and I have added it as

<!--    Scripts for google phone number validation utils -->
    <tags:script source="/js/GooglePhoneNumberUtils/phonenumberutil.js"/>
    <script src="http://closure-library.googlecode.com/svn/trunk/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>

I have no idea whats going on so please any help will be useful.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Khizar
  • 2,288
  • 5
  • 32
  • 53
  • If you don't want your users to download all those 220 KiloBytes in their web browsers I can suggest you use a lighter (70 KB) port of this library: https://github.com/halt-hammerzeit/libphonenumber-js – catamphetamine Dec 02 '16 at 08:47

1 Answers1

5

First include 'base.js', then 'phonenumberutil.js'

Engineer
  • 47,849
  • 12
  • 88
  • 91