RegularExpressionValidator Example in ASP.NET | Numeric field validation using RegularExpressionValidator

RegularExpressionValidator Example in ASP.NET

In this example i have given example on how to validate numeric field using regular expression server side validator in ASP.NET. 

RegularExpressionValidator required validation expression, control to validation, error message, id and run at attributes. 


Output:
RegularExpressionValidator Example in ASP.NET | Numeric field validation using RegularExpressionValidator
RegularExpressionValidator Example in ASP.NET | Numeric field validation using RegularExpressionValidator
ASP.NET CODE:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RegularExpressionValidator.aspx.cs" Inherits="RequiredFieldValidator" %>

<!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>
    
        <table style="width:50%;">
            <tr>
                <td>
                    <b>Enter Number:</b></td>
                <td>
                    <asp:TextBox ID="txtNumbers" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                        ControlToValidate="txtNumbers" ErrorMessage="Please Enter Numbers Only" 
                        ValidationExpression="^[0-9]*$"></asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    <asp:Button ID="btnNumbersCheck" runat="server" Text="Check Numbers" />
                </td>
            </tr>
        </table>
    
    </div>
    </form>
</body>
</html>



csharp



Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar