Click here to Skip to main content
14,825,800 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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
Posted

1 solution

Hi here i am giving the code in c#,

May be it will be help full for you.

C#
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;
            }
           
        }


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.
   
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900