Regular expression for validating integer value

Regular expressions are a good way to validate text fields such as names, addresses, phone numbers, and other user information. You can use them to constrain input, apply formatting rules, and check lengths.
You can use the System.Text.RegularExpressions.Regex class for validate any input string for any specific format.
The following example will allow you to Input Integer Number only.

[C#]

using System.Text.RegularExpressions;
 
public static bool CheckNumber(string strNumber)
        {
            string MatchNumberPattern = "\d+";
            if (strNumber!= null) return Regex.IsMatch(strNumber, MatchNumberPattern );
            else return false;
        }

[VB.NET]

Public Shared Function CheckNumber (ByVal strNumber As String) As Boolean
        Dim MatchNumberPattern As String = "\d+"       
  If strNumber IsNot Nothing Then
            Return Regex.IsMatch(strNumber , MatchNumberPattern)
        Else
            Return False
        End If
    End Function

More on Regular Expressions

Author: Ankur

Have worked primarily in the domain of Calling, CRM and direct advertisers services. My technological forte is Microsoft Technologies especially Dot Net (Visual Studio 2003, 2005, 2008, 2010 and 2012) and Microsoft SQL Server 2000,2005 and 2008 R2. My Area of Expertise is in C#. Net, VB.Net, MS-SQL Server, ASP. Net, Silverlight, HTML, XML, Crystal Report, Active Reports, Infragistics, Component Art, ComponeOne, Lead Tools etc.