-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhoneNumber.java
28 lines (22 loc) · 958 Bytes
/
PhoneNumber.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package kr.co.freeism;
import org.junit.Test;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;
/**
* @author freeism
* @since 15. 4. 24.
*/
public class PhoneNumber {
public void test() throws NumberParseException {
String numberStr = "01012347777";
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
Phonenumber.PhoneNumber proto = phoneUtil.parse(numberStr, "KR");
System.out.println(phoneUtil.format(proto, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
System.out.println(phoneUtil.format(proto, PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
System.out.println(phoneUtil.format(proto, PhoneNumberUtil.PhoneNumberFormat.E164));
System.out.println(phoneUtil.formatOutOfCountryCallingNumber(proto, "KR"));
boolean isValid = phoneUtil.isValidNumber(proto); // returns true
System.out.println(isValid);
}
}