C# Code
protected void btnValidate_Click(object sender, EventArgs e)
{
string strRegexpNumber = @"^[0-9 ]*$";
if (Regex.IsMatch(txtNumber.Text, strRegexpNumber))
{
lblMessage.Text = "Valid Number";
lblMessage.ForeColor = System.Drawing.Color.Green;
}
else
{
lblMessage.Text = "Invalid Number";
lblMessage.ForeColor = System.Drawing.Color.Red;
}
}
ASPX Page
<div>
Number<br />
<asp:TextBox ID="txtNumber" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnValidate" runat="server" Text="Validate" OnClick="btnValidate_Click" />
<br />
<br />
<asp:Label ID="lblMessage" runat="server"></asp:Label>
</div>
Output