Validate TextBox For Digits, Alphabets, AlphaNumeric Characters

September 06, 2013 // In: C#

In this tutorial, I’ll show you how to validate TextBox for Alphabets, Numbers or AlphaNumeric Values. If a TextBox is validated only for Numeric, It should not accept other characters. If  its validated for alphabets it should not accept other characters. Its better to make methods for validation.

validate textbox in c sharp

TextBox can be validated for Alphabets, Numbers and Alphanumeric characters via two methods. (I know there are plenty of methods, but two methods are commonly used)

Method 1

In Method 1 each character is scanned via foreach loop, if it finds any other character it stops looping and returns false.

AlphaNumeric

Digits

Alphabets

 Method 2

In Method 2, Regular Expression is used for validation. Namespace that will be used is

Alphabets

Digits

AlphaNumeric

Find string in an Array (C#)
Populate TreeView from Database using C#
  • Aryan

    function for float type input like 12.00 or 5.5