I am absolutely new to javascript development. What I need is validating a mobile number to enable sms after some time.
What I've found is googles libphonenumber
: https://code.google.com/p/libphonenumber/
There is a compiled javascript file (closure-compiler) in the source trunk an I thought, I could simply do the following:
function buildAndValidatePhone(phoneNumber, countryCode) {
var strIntlNumber = "invalid";
try {
var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
var regionCode = phoneUtil.getRegionCodeForCountryCode(countryCode);
var number = phoneUtil.parseAndKeepRawInput(phoneNumber, regionCode);
if (phoneUtil.isValidNumber(number)) {
var PNT = i18n.phonenumbers.PhoneNumberType;
var numberType = phoneUtil.getNumberType(number);
if (numberType == PNT.MOBILE) {
var PNF = i18n.phonenumbers.PhoneNumberFormat;
strIntlNumber = phoneUtil.format(number, PNF.E164);
strIntlNumber = strIntlNumber.replace('+','');
}
}
}
catch(ex) {
console.log(ex);
}
return strIntlNumber;
};
But I am getting a ReferenceError
- either i18n
is not defined or PhoneNumberUtil
is not defined.
How do I work with the compiled library?
Am I missing something or do I need to compile my code with the library?
I would appreciate any help, thanks in advance!