简体   繁体   中英

Regular Expression Validation with Default Text?

I have a watermark on my text box. I have put in required field validator and regex validator on the text box. Now the problem is I want that when watermark is present on the text box and user clicks the button, then user should see required message instead of error message.

But since there is some text in the text box, thus regex validator also gets fired. Can anyone tell me how can I achieve this ??

You can use this code. Its working fine.

<div>
    <asp:TextBox ID="txtCustomerName" runat="server"></asp:TextBox>
   <asp:RequiredFieldValidator ID="RrequiredFieldValidator1" runat="server"
    ErrorMessage="Please customer name" ControlToValidate="txtCustomerName" ForeColor="Red"
    Display="Dynamic">
   </asp:RequiredFieldValidator>
   <div style="clear:both"></div>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit Form" />
    <asp:TextBoxWatermarkExtender ID="wMarkExtndr"
    TargetControlID="txtCustomerName" WatermarkText="Enter customer name"
    runat="server">
    </asp:TextBoxWatermarkExtender>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM