25 December 2013

How to validate 10 digit mobile number in asp.net with regular expression control.

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <div>
        <table>
            <tr>
                <td>
                    <asp:Label ID="Label4" runat="server" Text="Mobile No:" Font-Bold="true"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txt_mobile" CssClass="textform" runat="server"></asp:TextBox>
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ForeColor="Red"
                        ControlToValidate="txt_mobile" Font-Size="X-Small" ErrorMessage="Please enter mobile number"
                        ValidationGroup="valid"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="rfvMobil1" Font-Size="XX-Small" ForeColor="Red" ControlToValidate="txt_mobile"
                        ValidationExpression="^[7-9][0-9](\s){0,1}(\-){0,1}(\s){0,1}[0-9]{1}[0-9]{7}$"
                        runat="server" ErrorMessage="Please enter Valid MobileNo" ValidationGroup="valid"
                        Display="Dynamic"></asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
                <td class="barhds">
                </td>
                <td align="left">
                    <asp:Button ID="btnsubmit" runat="server" Text="Submit" ValidationGroup="valid" />
                </td>
            </tr>
        </table>
    </div>
</asp:Content>







No comments:

Post a Comment