Wednesday, May 15, 2013

RegularExpression Validator asp.net

Validates whether the value of an associated input control matches the pattern specified by a regular expression.

Syntax :

  <asp:RegularExpressionValidator  
            ID="RegularExpressionValidator1" 
            runat="server"  
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" 
            ControlToValidate="txtemail" 
            ErrorMessage="Input valid email address!" 
           Display="Dynamic" > 
        </asp:RegularExpressionValidator> 


Where
              ValidationExpression =Define the validation expression(regular expression)
                 ControlToValidate= Name of control which have to validate.
                  ErrorMessage=custom  error message.






Example :    How to validate Email Address, numeric  digit  in asp.net



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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<head runat="server">
    <title>RegularExpressionValidator asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>
      RegularExpressionValidator asp.net-Validate Email Address
    </h1>
   
        <asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
         <asp:RegularExpressionValidator  
            ID="RegularExpressionValidator1" 
            runat="server"  
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" 
            ControlToValidate="txtemail" 
            ErrorMessage="Input valid email address!" 
           Display="Dynamic" > 
        </asp:RegularExpressionValidator> 
       
        <asp:Button ID="Button1" runat="server" Text="Submit" />
    </div>
   
        <div>
    <h1>
      RegularExpressionValidator asp.net-Validate 10 Numeric digit
    </h1>
   
        <asp:TextBox ID="txtdigit" runat="server"></asp:TextBox>
         <asp:RegularExpressionValidator  
            ID="RegularExpressionValidator2" 
            runat="server"  
            ValidationExpression="^[0-9]{10}" 
            ControlToValidate="txtdigit" 
            ErrorMessage="Input valid number" 
           Display="Dynamic" > 
        </asp:RegularExpressionValidator> 
       
        <asp:Button ID="Button2" runat="server" Text="Submit" />
    </div>
   
   
    </form>
</body>
</html>



Download Source code : RegularExpressionValidator asp.net

If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website

0 comments:

Post a Comment