开发者

How to make visible RegularExpressionValidator?

I woul开发者_Python百科d like to raise error by myself and use reqularexpressionvalidator to show it's text. (My idea is to reuse this control.) I don't remember what property should I use, and what to assign to show the message from control. Can anybody help me please? How to raise error for this control from code?


probably it is ErrorMessage

ErrorMessage="Please enter a 4 digit number!"

or with more details, use this syntax

    <asp:TextBox runat="server" id="txtNumber" />
    <asp:RegularExpressionValidator id="accessID"
    ControlToValidate = "ID of input control to validate"
    ValidationExpression = "the regular expression pattern to test against"
    ErrorMessage = "message to display in ValidationSummary control"
    Text = "message to display in control"
    ForeColor = "color value"
    BackColor = "color value"
    runat="server" />


Message shows the text next to the control Error shows the text after validation fails

Some people usually go with Message="*" and Error="Field cannot have special characters" and ValidationExpression is the regex to compare against, remember to set the ControlToValidate to the Id of your input control.


Assign the validator to a control using it's ControlToValidate property. Set the text using it's ErrorMessage property.

Then, if you'd like it to show, you can call Page.IsValid on the server, like this:

void ValidateBtn_Click(Object sender, EventArgs e) 
       {
          if (Page.IsValid) 
          {
            // do something
          }
       }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜