如何限制文本框的长度 [英] How to restrict length for a textbox
本文介绍了如何限制文本框的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想只在文本框中输入最多100个字符。我使用了以下代码,但它允许超过100个字符。任何人都可以指导我吗?
I want to enter maximum of 100 characters only in a textbox. I used the following code but it allows beyond 100 characters. Can any one guide me?
<asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" MaxLength="100"
OnTextChanged="TextBox3_TextChanged" Font-Size="Medium"
style="z-index: 1; left: 930px; top: 178px; position: absolute;height: 40px; width: 225px"></asp:TextBox>
谢谢。
Thanks.
推荐答案
这里有很好的例子
限制Textarea或文本字段中的字符数
或者你可以甚至尝试通过用maxlength
替换MaxLength
来修改代码
Wonderful example can be found here
Limit the Number of Characters in a Textarea or Text Field
or you can even try modifying code by replacingMaxLength
withmaxlength
删除属性, TextMode =MultiLine
remove the property, TextMode="MultiLine"
<asp:TextBox ID="TextBox3" runat="server" MaxLength="100"
OnTextChanged="TextBox3_TextChanged" Font-Size="Medium"
style="z-index: 1; left: 930px; top: 178px; position: absolute;height: 40px; width: 225px"></asp:TextBox>
如果你想要使用多行检查字符提交时使用
TextBox3.Text.Length
或使用正则表达式验证器作为文本框3并使用常规表达式:(\ | |。){0,10}
if you want to use multiline check no of characters on submit using
TextBox3.Text.Length
or use regular expression validator for text box3 and use regular expression : (\s|.){0,10}
如下
as follows
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox3" ErrorMessage="RegularExpressionValidator"
ValidationExpression="(\s|.){0,10}
这篇关于如何限制文本框的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文