What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 9212 |  Welcome, Guest!   Register  Login
Home > Tutorials > ASP.NET Tutorials > RegularExpressionValidator

Silverlight Tutorials | Report a Bug in the Tutorial
Found interesting? Add this to:


asp:RegularExpressionValidator control
RegularExpressionValidator validation control is used to make sure that a textbox will accept a predefined format of characters.
 
RegularExpressionValidator validation control is used to make sure that a textbox will accept a predefined format of characters. This format can be of any type like you@domain.com (a valid email address).

 

Following are main properties of the validation control.
ValidationExpression Gets or sets the regular expression that will be used to validate input control data.
ControlToValidate Gets or sets the input control to validate (eg. The ID value of asp:TextBox control).
Display Dynamic/Static. Used to indicate how the area of error message will be allocated.
Dynamic: Error message area will only be allocated when error will be displayed. Static: Error messagea area will be allocated in either case.
Enabled true/false. Gets or sets whether to enable the validation control or not.
ErrorMessage Gets or sets the text of the error message that will be displayed when validation fails (This is displayed when ValidationSummary validatoin control is used.).
Text Gets or sets the description of the error message text.
ValidationGroup Gets or sets the validation group it belongs to. This is used to group a set of controls.
SetFocusOnError true/false. Used to move focus on the control that fails the validation.
DEMO : RegularExpressionValidator Show Source Code
   
    
                    
        <asp:Label ID="lbl" AssociatedControlID="TextBox1" runat="Server" Text="Write into TextBox"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="Server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="req1" runat="Server" ControlToValidate="TextBox1" ErrorMessage="TextBox is Mandatory field" Text="Please write something in the Box."></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1" Text="Write your email" ErrorMessage="eg. you@domain.com"
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        <asp:Button ID="btnSubmit" runat="Server" OnClick="WriteTextBoxValue" Text="Submit" />                
        <asp:ValidationSummary ID="ValidationSummary" runat="Server" ShowMessageBox="true" />
                    





About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/26/2013 3:16:46 AM