Monday, 9 January 2012

Email and Website Validation Example

  <div>
            <asp:TextBox ID="TxtFax" runat="server" TabIndex="8" MaxLength="25" />
        </div>
        <div>
            <span class="EmptyMessage">
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Enter valid Email."
                    ControlToValidate="TxtEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                    SetFocusOnError="true">*</asp:RegularExpressionValidator></span> E-Mail
            :
        </div>
        <div>
            <asp:TextBox ID="TxtEmail" runat="server" TabIndex="9" MaxLength="50" Width="220" />
            <asp:Label ID="Label1" runat="server" Text="Ex: xyz@abc.com " Font-Bold="True" ForeColor="Red"></asp:Label>
        </div>
        <div>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="Enter valid URL"
                ControlToValidate="TxtWebSite" CssClass="EmptyMessage" SetFocusOnError="true"
                ValidationExpression="^(http(?:s)?\:\/\/[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:\/?|(?:\/[\w\-]+)*)(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$">*</asp:RegularExpressionValidator>
            Web Site :
        </div>
        <div>
            <asp:TextBox ID="TxtWebSite" runat="server" TabIndex="10" MaxLength="25" Width="220" />
            <asp:Label ID="Label2" runat="server" Text="Ex: http://www.abc.com " Font-Bold="True"
                ForeColor="Red" />
        </div>

No comments:

Post a Comment