Source/NFX/Parsing/DataEntryUtils.cs
/// <summary>
/// Returns true if the value is a valid non-null/empty telephone
/// </summary>
Returns true if the value is a valid non-null/empty telephone
Returns true if the value is a valid non - null / empty telephone
public static bool CheckTelephone(string phone)
    {
      if (String.IsNullOrEmpty(phone)) return false;
      if (phone.Length < 7) return false;
      char c;
      var hasFirstParenthesis = false;
      var hasSecondParenthesis = false;
      var prevIsSpecial = false;
      var area = false;
      var inParentheses = false;
      for (int i = 0; i < phone.Length; i++)
      {
        c = phone[i];
        if (i == 0)
        {
          if (Char.IsWhiteSpace(c)) return false;
          if (c == '+')
          {
            prevIsSpecial = true;
            continue;
          }
          else
            area = true;
        }
        if (i == (phone.Length - 1) && !IsLatinLetterOrDigit(c)) return false;
        if (c == '(')
        {
          if (hasFirstParenthesis || hasSecondParenthesis || prevIsSpecial) return false;
          hasFirstParenthesis = true;
          inParentheses = true;
          continue;
        }
        if (c == ')')
        {
          if (hasSecondParenthesis || prevIsSpecial) return false;
          hasSecondParenthesis = true;
          prevIsSpecial = true;
          inParentheses = false;
          continue;
        }
        if (c == '-' || c == '.')
        {
          if (prevIsSpecial || inParentheses) return false;
          prevIsSpecial = true;
          continue;
        }
        if (c == ' ')
        {
          if ((prevIsSpecial && phone[i - 1] != ')') || inParentheses) return false;
          prevIsSpecial = true;
          continue;
        }
        if (area)
        {
          for (int j = 0; j < 3 && i < phone.Length - 2; j++)
          {
            c = phone[i + j];
            if (!Char.IsDigit(c)) return false;
          }
          if (inParentheses && phone[i + 3] != ')') return false;
          area = false;
          i = i + 2;
          continue;
        }
        if (!IsLatinLetterOrDigit(c)) return false;
        prevIsSpecial = false;
      }
      if (inParentheses || (hasSecondParenthesis && !hasFirstParenthesis))
        return false;
      return true;
    }
public static bool CheckTelephone ( string phone ) { if ( String . IsNullOrEmpty ( phone ) ) return false ; if ( phone . Length < 7 ) return false ; char c ; var hasFirstParenthesis = false ; var hasSecondParenthesis = false ; var prevIsSpecial = false ; var area = false ; var inParentheses = false ; for ( int i = 0 ; i < phone . Length ; i ++ ) { c = phone [ i ] ; if ( i == 0 ) { if ( Char . IsWhiteSpace ( c ) ) return false ; if ( c == ' ' ) { prevIsSpecial = true ; continue ; } else area = true ; } if ( i == ( phone . Length - 1 ) && ! IsLatinLetterOrDigit ( c ) ) return false ; if ( c == ' ' ) { if ( hasFirstParenthesis || hasSecondParenthesis || prevIsSpecial ) return false ; hasFirstParenthesis = true ; inParentheses = true ; continue ; } if ( c == ' ' ) { if ( hasSecondParenthesis || prevIsSpecial ) return false ; hasSecondParenthesis = true ; prevIsSpecial = true ; inParentheses = false ; continue ; } if ( c == ' ' || c == ' ' ) { if ( prevIsSpecial || inParentheses ) return false ; prevIsSpecial = true ; continue ; } if ( c == ' ' ) { if ( ( prevIsSpecial && phone [ i - 1 ] != ' ' ) || inParentheses ) return false ; prevIsSpecial = true ; continue ; } if ( area ) { for ( int j = 0 ; j < 3 && i < phone . Length - 2 ; j ++ ) { c = phone [ i + j ] ; if ( ! Char . IsDigit ( c ) ) return false ; } if ( inParentheses && phone [ i + 3 ] != ' ' ) return false ; area = false ; i = i + 2 ; continue ; } if ( ! IsLatinLetterOrDigit ( c ) ) return false ; prevIsSpecial = false ; } if ( inParentheses || ( hasSecondParenthesis && ! hasFirstParenthesis ) ) return false ; return true ; }
Returns true if the value is a valid non-null/empty telephone
Returns true if the value is a valid non - null / empty telephone
phone
string