如何使用RegularExpressionValidator验证字段的条目? [英] How can I validate an entry of a field by using RegularExpressionValidator?
问题描述
嘿伙计
我使用此代码:
Hey guys
I used this code:
<asp:TextBox ID="_textBoxCustomerNr" runat="server" Width="150"></asp:TextBox>
<br />
<asp:RegularExpressionValidator ID="_regularExpressionValidatorCustomerNr" runat="server" Display="Dynamic" ControlToValidate="_textBoxCustomerNr" ValidationExpression="^[\s\S]{3,50}$" EnableClientScript="false"
ErrorMessage="Customer Nr. too short!">
</asp:RegularExpressionValidator>
现在我想要的是:
每当我在textBox _textBoxCustomerNr中输入内容时,应验证RegularExpressionValidator并显示错误消息。
这适用于第一个文本框,但不适用于其他文本框,为什么?我忘记了什么?我将EnableClientScript变为每个文本框的true,但这没有任何帮助。现在它是变成了假 - 仅限第一个。
我会很乐意为你提供帮助。
谢谢
valentigra
Now what I want:
whenever I enter something int the textBox _textBoxCustomerNr, the RegularExpressionValidator should be validated and the error message should be displayed.
this works for the first textbox but not for the others, why? Did I forget something? I turned EnableClientScript to "true" for every textbox, but that doesn't help anything. Now it's turned into "false" - only for the first one.
I would be very happy for every help.
Thanks
valentigra
推荐答案
EnableClientScript = false
ErrorMessage = 客户编号。太短了! >
< / asp:RegularExpressionValidator >
" EnableClientScript="false" ErrorMessage="Customer Nr. too short!"> </asp:RegularExpressionValidator>
现在我想要的是:
每当我在textBox _textBoxCustomerNr中输入内容时,应验证RegularExpressionValidator并显示错误消息。
这适用于第一个文本框,但不适用于其他文本框,为什么?我忘记了什么?我将EnableClientScript变为每个文本框的true,但这没有任何帮助。现在它是变成了假 - 仅限第一个。
我会很乐意为你提供帮助。
谢谢
valentigra
Now what I want:
whenever I enter something int the textBox _textBoxCustomerNr, the RegularExpressionValidator should be validated and the error message should be displayed.
this works for the first textbox but not for the others, why? Did I forget something? I turned EnableClientScript to "true" for every textbox, but that doesn't help anything. Now it's turned into "false" - only for the first one.
I would be very happy for every help.
Thanks
valentigra
您好valentigra,
如果您希望其他文本框验证相同的条件,那么您应该使用另一个asp:RegularExpressionV alidator
用控制> ControlToValidate =_ Text2
属性。
因为你设置了_regularExpressionValidatorCustomerNr
属性ControlToValidate只有一个文本框_textBoxCustomerNr,你不能指望其他文本框遵循相同的验证。
对于每个文本框,你应该有单独的Regularexpression验证控件。 />
更新后的解决方案:
EnableClientScript =True也不适用于你?
希望这对你有所帮助。
问候,
RK
Hi valentigra,
If you want other text box to validate the same condition then you should use anotherasp:RegularExpressionValidator
control withControlToValidate ="_Text2"
attribute.
Since you have set_regularExpressionValidatorCustomerNr
with attribute ControlToValidate to only one textbox that is _textBoxCustomerNr, you cant expect other textbox to follow the same validation.
For every text box you should have individual Regularexpression validation control.
Updated solution:
EnableClientScript="True" also did not work for you?
Hope this helps you a bit.
Regards,
RK
您好valentigra,
解决方案1是最好的,您只需设置所有文本框的验证组属性也适用于您拥有的按钮执行所有这些验证。
如果要使用RegularExpressionValidator进行验证,则必须对每个文本框进行单独的正则表达式验证。
或者您可以以编程方式编写验证函数并为每个文本框条目调用该函数。?
Hi valentigra,
Solution 1 is best , you just need to set validation group property of all text boxes same also for button on which you have to perform all this validations.
You must need separate Regular Expression Validation For each textbox if you want to do validation using RegularExpressionValidator.
Or you can write validation function programatically and call that function for each textbox entry.?
回复我是否有效?
reply me If it works or not ?
这篇关于如何使用RegularExpressionValidator验证字段的条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!