ASP普通防爆pression验证的多行文本框 [英] ASP Regular Expression Validator for Multi-line textbox
问题描述
我需要验证的文本框输入的长度。
I need to validate the length of input of a textbox.
最大长度属性并不多行文本框工作。
The max length property does not work for Multiline textboxes.
常规前pression我拥有的是:
The regular expression I have is:
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="The notes has exceeded maximum length."
ControlToValidate="txtNotes" Display="Dynamic"
ValidationExpression=".{0,500}" ValidationGroup="PO">
*</asp:RegularExpressionValidator>
我遇到的问题是,当一个新行输入到验证报告问题的文本框。
The problem I'm having is when a new line is entered into the textbox the validator reports a problem.
我需要添加到ValidationEx pression忽略回车?
What would I need to add to the ValidationExpression to ignore carriage returns?
感谢
推荐答案
修改 {0,500}
到 [\\ S \\ S] {0,500 }
。需要注意的是回车将不完全是的忽略; 的他们还是会朝500个字符的限制数。
Change .{0,500}
to [\s\S]{0,500}
. Note that carriage returns won't exactly be ignored; they'll still count toward the 500-character limit.
当然,如果500个字符是数据库字段的大小,这正是你想要的行为。
Of course, if 500 characters is the size of your database field, that's exactly the behavior you want.
这篇关于ASP普通防爆pression验证的多行文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!