文本框不接受空格 [英] textbox don't accept space

查看:87
本文介绍了文本框不接受空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了一个包含文本框的网页,当用户需要类型空间时,它是b $ b,这是我的代码:/ b $ b谢谢

这是我的代码:

i design a webpage that have textbox,
when user want type space it's not accpet,
thanks
this is my code:

 <table align="center" cellspacing="5px" class="tbl-inside-form">
        <tr>
            <td>
                name
            </td>
            <td>
                <div class="frame-white-right">
                </div>
                <div class="frame-white-body form-txt-body">
                    <asp:TextBox ID="name" Text="" runat="server"></asp:TextBox>
                </div>
                <div class="frame-white-left">
                </div>
            </td>
        </tr>
        <tr>
            <td>
family
            </td>
            <td>
                <div class="frame-white-right">
                </div>
                <div class="frame-white-body form-txt-body">
                    <asp:TextBox ID="family" Text="" runat="server"></asp:TextBox>
                </div>
                <div class="frame-white-left">
                </div>
            </td>
        </tr>
        <tr>
            <td>
                tell
            </td>
            <td>
                <div class="frame-white-right">
                </div>
                <div class="frame-white-body form-txt-body">
                   <asp:TextBox ID="tel_no" Text="" runat="server"></asp:TextBox>
                </div>
                <div class="frame-white-left">
                </div>
            </td>
        </tr>
         <tr>
            <td>
                email
            </td>
            <td>
                <div class="frame-white-right">
                </div>
                <div class="frame-white-body form-txt-body">
                    <asp:TextBox ID="email" Text="" runat="server"></asp:TextBox>
                </div>
                <div class="frame-white-left">
                </div>
            </td>
        </tr>
        <tr>
            <td>
                comment
            </td>
            <td>
                <asp:TextBox ID="description" Text="" CssClass="text-area-form" runat="server" TextMode="MultiLine"></asp:TextBox>
            </td>
        </tr>
        <tr>
            
            <td colspan="2">
                <div class="frame-btn-left">
                            </div>
                            <div class="frame-btn-body">
                                <asp:Button ID="btn_submit" runat="server" Text="ثبت" onclick="btn_submit_Click" />
                            </div>
                            <div class="frame-btn-right">
                            </div>
            </td>
        </tr>
    </table>

推荐答案

为此需要使用 RegularExpressionValidator 。请参阅此解决方案:

文本框上的验证(无空格) [ ^ ]
You need to use RegularExpressionValidator for this purpose.See this solution:
validation on textbox (no space)[^]


请参阅此链接,它可以帮助您

如何避免文本框中的sapce
Please See this link which may help you
How to avoid sapce in textbox


你可以使用它.. 。



you may use this...

void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
     if ((sender as TextBox).SelectionStart == 0)
          e.Handled = (e.KeyChar == (char)Keys.Space);
     else
          e.Handled = false;
}


这篇关于文本框不接受空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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