Java Number Format formatPhoneNo(String country, String area, String number, String inline)

Here you can find the source of formatPhoneNo(String country, String area, String number, String inline)

Description

format Phone No

License

Open Source License

Declaration

public static String formatPhoneNo(String country, String area, String number, String inline) 

Method Source Code

//package com.java2s;

public class Main {

    public static String formatPhoneNo(String country, String area, String number, String inline) {
        StringBuffer sb = new StringBuffer();
        boolean first = true;
        if (country != null)
            country = country.trim();//from  w ww  .  j  a  v  a2s.co  m
        if (area != null)
            area = area.trim();
        if (number != null)
            number = number.trim();
        if (inline != null)
            inline = inline.trim();
        //if (JFCheck.isEmpty(country) == false) {
        if ((country != null) && !country.trim().equals("")) {
            sb.append(country);
            first = false;
        }
        //if (JFCheck.isEmpty(area) == false) {
        if ((area != null) && !area.trim().equals("")) {
            if (first == false)
                sb.append("-");
            sb.append(area);
            first = false;
        }
        //if (JFCheck.isEmpty(number) == false) {
        if ((number != null) && !number.trim().equals("")) {
            if (first == false)
                sb.append("-");
            if (number.length() > 4) {
                sb.append(number.substring(0, number.length() - 4));
                sb.append("-");
                sb.append(number.substring(number.length() - 4));
            } else {
                sb.append(number);
            }
            first = false;
        }
        //if (JFCheck.isEmpty(inline) == false) {
        if ((inline != null) && !inline.trim().equals("")) {
            sb.append("(" + inline + ")");
        }
        return sb.toString();
    }
}

Related

  1. formatPartialName(String name, int numberOfCharacters)
  2. formatPattern(String number, String pattern)
  3. formatPct(final Number amount)
  4. formatPercentage(Number numerator, Number denominator)
  5. formatPhone(String phoneNumber, String formattingPattern, String countryCode)
  6. formatPhoneNumber(String number)
  7. formatPhoneNumber(String phoneNumber)
  8. formatPrintIntegerToString(long number, boolean printCommasP, boolean printSignP, int radix, int mincol, char padchar, char commachar, int commainterval)
  9. formatRowKey(final long number, final int digits, byte[] dest)