Click here to Skip to main content
15,913,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to using this codes but some problems......


C#
private void txtbank_TextChanged(object sender, TextChangedEventArgs e)
       {

           if (System.Text.RegularExpressions.Regex.IsMatch(txtbank.Text, "^[a-zA-Z]+$"))
           {
           }
           else
           {
               txtbank.Text = txtbank.Text.Remove(txtbank.Text.Length -1);

               //MessageBox.Show("Enter only Alphabets");
           }
       }


shows an Exception StartIndex cannot be less than zero.
Posted
Updated 1-Nov-12 22:46pm
v2

1 solution

Because you have empty text in control. Add condition to else
C#
!string.IsNullOrEmpty(txtbank.Text)

and then use Regex.Replace not string.Remove, cause you can change string in text box anywhere not only at the end right?
 
Share this answer
 

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