1 February 2014

Validate textbox to allow only numeric values using RegularExpressionValidator

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="UI.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <center>
            <asp:TextBox ID="txt_number" runat="server"></asp:TextBox>
            <asp:RegularExpressionValidator id="RegularExpressionValidator1"
                   ControlToValidate="txt_number"
                   ValidationExpression="\d+"
                   Display="Static"
                   EnableClientScript="true"
                   ErrorMessage="Please enter numbers only"
                   runat="server"/>
        </center>
    </div>
    </form>
</body>
</html>

No comments:

Post a Comment