ASP.NET

전화번호, 핸드폰 번호 나누기 함수

bang2001 2016. 1. 21. 15:56
#region [DevideTelNo] 전화번호 분할 ex) input : 07036889188 -> output : 070 3688 9188, output is array
    /// <summary>
    /// [DevideTelNo] 전화번호 분할
    /// ex) input : 07036889188 -> output : 070 3688 9188
    /// output is array
    /// </summary>
    public string[] DevideTelNo(string TelNo)
    {
        string[] output = new string[3];
        
        output[0] = string.Empty;
        output[1] = string.Empty;
        output[2] = string.Empty;
        //유효성 검사
        if (string.IsNullOrEmpty(TelNo) || TelNo.Length < 9)
        {
            return output;
        }
        //첫번째 자리
        if (TelNo.StartsWith("02"))
        {
            output[0] = TelNo.Substring(0, 2);
            TelNo = TelNo.Substring(2, TelNo.Length-2);
        }
        else
        {
            output[0] = TelNo.Substring(0, 3);
            TelNo = TelNo.Substring(3, TelNo.Length-3);
        }
        //가운데 자리
        if (TelNo.Length == 8)
        {
            output[1] = TelNo.Substring(0, 4);
            TelNo = TelNo.Substring(4, TelNo.Length-4);
        }
        else
        {
            output[1] = TelNo.Substring(0, 3);
            TelNo = TelNo.Substring(3, TelNo.Length-3);
        }
        //마지막 자리
        output[2] = TelNo.Substring(0, 4);
        return output;
    }
    #endregion