Languages
[Edit]
EN

C# / .NET - check if string contains only letters

0 points
Created by:
Zeeshan-Peel
850

In this article, we would like to show you how to check if string contains only letters in C#.

Quick solution:

or:

 

1. Practical example using regex

Edit

In this example, we use a regular expression (regex) with IsMatch() to check if the strings contain only letters.

Output:

2. Using All() with IsLetter() method

Edit

In this example, we use All() from System.Linq with IsLetter() method to check if all characters in strings are letters.

Output:

References

Edit
  1. Regex.IsMatch Method (System.Text.RegularExpressions) | Microsoft Docs
  2. Enumerable.All<TSource>() Method (System.Linq) | Microsoft Docs
  3. Char.IsLetter Method (System) | Microsoft Docs
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join