Press right arrow

String phoneNumber = "044 668 18 00" // Switzerland phone number

PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();

PhoneNumber phoneNumberProto = 
    phoneUtil.parse(phoneNumber, "CH"); // CH - Switzerland country code

boolean isValid = 
    phoneUtil.isValidNumber(phoneNumberProto); // returns true

// Produces "+41 44 668 18 00"
phoneUtil.format(phoneNumberProto, PhoneNumberFormat.INTERNATIONAL

// Produces "044 668 18 00"
phoneUtil.format(phoneNumberProto, PhoneNumberFormat.NATIONAL

// Produces "+41446681800"
phoneUtil.format(phoneNumberProto, PhoneNumberFormat.E164)

Press right arrow

String phoneNumber = "044 668 18 00" // Switzerland phone number

PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();

PhoneNumber phoneNumberProto = 
    phoneUtil.parse(phoneNumber, "CH"); // CH - Switzerland country code

boolean isValid = 
    phoneUtil.isValidNumber(phoneNumberProto); // returns true

// Produces "+41 44 668 18 00"
phoneUtil.format(phoneNumberProto, PhoneNumberFormat.INTERNATIONAL

// Produces "044 668 18 00"
phoneUtil.format(phoneNumberProto, PhoneNumberFormat.NATIONAL

// Produces "+41446681800"
phoneUtil.format(phoneNumberProto, PhoneNumberFormat.E164)

test-deck

By Dmytro Danylyk