Verifying that a string contains only letters in C#

Only letters:

Regex.IsMatch(input, @"^[a-zA-Z]+$");
Regex.IsMatch(input, @"^[a-zA-Z]+$");
  1. <code>
  2. Regex.IsMatch(input, @"^[a-zA-Z]+$");
  3. </code>
<code>
Regex.IsMatch(input, @"^[a-zA-Z]+$");
</code>
Only letters and numbers:

Regex.IsMatch(input, @"^[a-zA-Z0-9]+$");
Regex.IsMatch(input, @"^[a-zA-Z0-9]+$");
  1. <code>
  2. Regex.IsMatch(input, @"^[a-zA-Z0-9]+$");
  3. </code>
<code>
Regex.IsMatch(input, @"^[a-zA-Z0-9]+$");
</code>
Only letters, numbers and underscore:

Regex.IsMatch(input, @"^[a-zA-Z0-9_]+$");
Regex.IsMatch(input, @"^[a-zA-Z0-9_]+$");
  1. <code>
  2. Regex.IsMatch(input, @"^[a-zA-Z0-9_]+$");
  3. </code>
<code>
Regex.IsMatch(input, @"^[a-zA-Z0-9_]+$");
</code>

Popular posts from this blog

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

C# Crop white space from around the image

The specified version string contains wildcards, which are not compatible with determinism.