限制文本框的字符数 [英] Limit the number of characters of a textbox

查看:180
本文介绍了限制文本框的字符数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/1334286/specifying-maxlength-for-multiline-textbox\">Specifying MAXLENGTH多行文本框结果
  如何设置最大长度为多行TextBox?

我想限制的文本框的字符数。

I want to limit the number of characters of a text box.

为此我使用了

<asp:textbox id="txtAdmissionDate" runat="server" MaxLength="5"> </asp:textbox>

它的正常工作。但是,当我加入的TextMode =多行属性吧,maxlenth是行不通的。

It's working fine. But when i add TextMode="MultiLine" attribute to it, the maxlenth is not working.

请帮助

推荐答案

如果您希望让用户知道他是否超出字符作为他写道,你可以使用JavaScript函数连接到关键preSS事件的金额。该功能将测试输入的长度和取消字符渲染,如果maxlenght达到。

If you want to let the user know if he exceeded the amount of characters as he writes, you could use a javascript function attached to keypress event. This function would test the length of the input and cancel the character rendering if the maxlenght was reached.

另一种选择是使用RegularEx pressionValidator控件来验证上提交的投入。

Another option is to use RegularExpressionValidator control to validate the input on submit.

在我看来,第一个选项是好过得多。

In my opinion, the first option is much more better.

我不加入任何code,因为谷歌是充满了各种口味的例子,这是一个很常见的任务。

I'm not adding any code since google is full of examples for all tastes, this is a very common task.

这里你有一个示例搜索可能的帮助。

Here you have a sample search that might help.

或者你可以从<一个更多信息href=\"https://www.google.com.ar/#hl=es&sclient=psy-ab&q=multiline+textbox+maxlength&oq=multiline+textbox+maxlength&aq=f&aqi=&aql=&gs_sm=3&gs_upl=5132l5288l0l5522l2l2l0l0l0l1l227l227l2-1l1l0&gs_l=serp.3...5132l5288l0l5522l2l2l0l0l0l1l227l227l2-1l1l0.llsin.&pbx=1&fp=1&biw=1399&bih=790&bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&cad=b\"相对=nofollow>在这里也

这篇关于限制文本框的字符数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆