Here we will see how to use regular expression in .NET to validate input.

Regular Expressions Elements:

Example Regular Expression :

  1. Numeric input: ^\d+$ Consists of one or more decimal digits ; example 9 or 9873455.
  2. Credit Card Number: ^\d{4}-?\d{4}-?\d{4}-?\d{4}$
  3. Email Address: ^[\w-]+@([\w-]+\.)+[\w-]+$

Using in C#: