Wednesday 8 October 2014

Regular Expression Validation Control in Asp.Net C#

No comments    
categories: ,
REGULAR EXPRESSION

RegularExpressionValidator control determine whether an input control's entered value matches a pattern defined by a regular expression.

 this validation control is very useful to check predictable sequences of characters. 

                       DEMO


Html Coding


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table><tr><td>
        <asp:Label ID="Label1" runat="server"
Text="Mobile Number"></asp:Label>
        </td><td>
            <asp:TextBox ID="txtMobile"
 runat="server"></asp:TextBox>
            <asp:RegularExpressionValidator
ID="RegularExpressionValidator2"
 runat="server"
                 ControlToValidate="txtMobile"
ErrorMessage="Invalid Number"

                ValidationExpression="^((\\+91-?)|0)?[0-9]{10}$">
</asp:RegularExpressionValidator>
        </td></tr>

        <tr><td>
            <asp:Label ID="Label2" runat="server" Text="Email ID"></asp:Label>
            </td><td>
                <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
 runat="server" ControlToValidate="txtEmail"
                                     ErrorMessage="Invalid Email ID"
                    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
            </td></tr>
        <tr><td colspan ="2">
            <asp:Button ID="Button1" runat="server" Text="Save" />
            </td></tr>

    </table>
    </div>
    </form>
</body>
</html>

Mobile Number Validation Expression :

                                                    ^((\\+91-?)|0)?[0-9]{10}$



regularexpressionvalidator is mostly use for validate email address, social security number, telephone number, postal (zip) code etc.













 




     
             




0 comments:

Post a Comment