skip to Main Content
(31) 98739-9637

Verificar se String possui número ou caracteres.

Exemplo:

 public void verifica(string texto)
  {
    if (this.contemLetras(texto) && this.contemNumeros(texto))
    {
      //Contem Letras e Números
    }
    else if (this.contemLetras(texto))
    {
      //Contem somente letras
    }
    else if (this.contemNumeros(texto))
    {
      //Contem somente numeros
    }
  }
  
  public bool contemLetras(string texto)
  {
    if (texto.Where(c => char.IsLetter(c)).Count() > 0)
      return true;
    else
      return false;
  }

  public bool contemNumeros(string texto)
  {
    if (texto.Where(c => char.IsNumber(c)).Count() > 0)
      return true;
    else
      return false;
  }

voce pode chama-lo assim:

 string texto1 = "asdfr";
    string texto2 = "123";
    string texto3 = "13qew12";

    this.verifica(texto1);
    this.verifica(texto2);
    this.verifica(texto3);

Fonte: Forum msdn

Back To Top