Issue with Regular Expression Validator for text b

2020-05-07 08:24发布

Im having issues with the RegularExpressionValidator in my code!

I have 2 text boxes in my html page and in the code i have the sql command that inserts the parameters to the DB, the issue is that if i put a special character to the text box the sql stops because i need the validators, so i tried validating like this.

Insert the files number.
<asp:TextBox ID="TextBox1" runat="server" MaxLength="10" ></asp:TextBox>

Whats the users Name <br />
<asp:TextBox ID="TextBox2" runat="server" MaxLength="10"></asp:TextBox>

The validator is defined as:

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
    ErrorMessage="RegularExpressionValidator" ValidationExpression="^\d+$" 
    ControlToValidate="TextBox1"></asp:RegularExpressionValidator>

But when loading it ignores my validation expresion.

Please what is missing.

Thanks

2条回答
Juvenile、少年°
2楼-- · 2020-05-07 09:00

If you want to see a mark next to the field when validation fails, you should set the Text property of the validator:

<asp:RegularExpressionValidator ID="rev1" runat="server" ControlToValidate="TextBox1" Text="*" />

Also, if you want to see the error message, you must have a ValidationSummary in your form.

查看更多
家丑人穷心不美
3楼-- · 2020-05-07 09:05

I checked everything and finally got it,

I had to add to my web.config the following:

<configuration>
  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>
</configuration>

And that solved my issues

查看更多
登录 后发表回答