Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
google-libphonenumber
node v9.11.2
version:
2.0.0
endpoint
share
tweet
let nr = '06 - 83164677' let country = 'NL' const phoneno = '+' + nr.replace(/[^0-9\-\(\)+]+/g, '').trim().replace(/^[0+]+/, '') console.log(phoneno) const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance() const number = phoneUtil.parseAndKeepRawInput(phoneno) console.log(number.getCountryCode()) if (phoneUtil.isValidNumber(number)) { console.log("valid") console.log(phoneUtil.format(number, require('google-libphonenumber').PhoneNumberFormat.E164)) } else { console.log("invalid, try with country", country) const numbercc = phoneUtil.parseAndKeepRawInput(nr, country) console.log(phoneUtil.format(numbercc, require('google-libphonenumber').PhoneNumberFormat.E164)) } //
Created from: https://npm.runkit.com/google-libphonenumber
Loading…
no comments
sign in
to comment