当我使用Javascript输入特殊字符时如何禁用和启用文本框 [英] how to disable and enable a textbox when i enter a special character using Javascript

查看:74
本文介绍了当我使用Javascript输入特殊字符时如何禁用和启用文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果我在文本框中输入任何特殊字符并单击添加按钮,我想取消添加按钮,我想取消添加按钮,并且如果刷新页面并输入不带特殊字符的名称,我想启用添加按钮.

我有带multiline = true的文本框,并且在aspx页面中有一个按钮,当我输入任何字符串时,例如,如果我在文本框中输入-ravi @ 123,并且如果我单击添加按钮,我想在刷新时禁用添加按钮第n页输入字符串,例如-Ravi123不能启用添加按钮,我希望使用JavaScript完成此操作,有人可以帮我吗


谢谢
Ravi

hi ,

i want to disble the add button if i enter any special character in textbox and on click of add button i want to disbale the add button , and if i refresh the page and enter the name with out special character i want to enable the Add button .

i have textbox with multiline=true, and a button in my aspx page, when i enter any string , example if i enter -ravi@123 into the textbox and if i click add button i want to disable the add button if i refresh the page n enter the string like - Ravi123 not the add button could be enable, i want this to be done using JavaScript, can any one help me on this


Thanks
Ravi

推荐答案

我在这里用c#提供代码,

可能对您有帮助.

Hi here i am giving the code in c#,

May be it will be help full for you.

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
              if (!char.IsLetterOrDigit(e.KeyChar) & (e.KeyChar != 8))
            {
                if (char.IsLetterOrDigit(e.KeyChar))
                {
                    e.Handled = true;
                    button1.Enabled = true;
                }
                else
                {
                    button1.Enabled = false;
                }
                e.Handled = true;
                button1.Enabled = false;
            }
            else
            {
                button1.Enabled = true;
            }
           
        }



尝试使用此代码.

在此示例中,它将接受后背空间.

如果您输入类似ravi @的按钮将被禁用.

如果您输入退格键,将选择@并启用按钮.

在开始位置,如果您输入了任何特殊字符按钮,将被禁用.



Try with this code.

In this example it will accept back sapce.

if you enter like ravi@ button will be disabled.

if you enter backspace @ will be delected and button will be enabled.

At the starting position if you entered any special character button will be disabled.


这篇关于当我使用Javascript输入特殊字符时如何禁用和启用文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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